Using ajax control (CollapsiblePanelExtender) in custom server control


I'm trying to write a server control that contains the collapsiblePanelExtender from the ajax toolkit.  But I have the following error when i try to show this control:

Extender control 'ctl00$contentHolder$ctl00$Ant_baseModule1_cpeDemo' is not a registered extender control. Extender controls must be registered using RegisterExtenderControl() before calling RegisterScriptDescriptors().

I have no idea what i must add or change to make it working.  Anyone who has an idea?  Or maybe I'm doing it all wrong?

This is my code:

   Protected Overrides Sub Render(ByVal output As HtmlTextWriter)

        'Detail Label
        Dim aDetailLabel As New Label
        aDetailLabel.ID = Me.UniqueID & "_lblHeaderDetails"
        aDetailLabel.Text = "(Show Details...)"

        'Header Panel
        Dim headerPanel As New Panel
        headerPanel.ID = Me.UniqueID & "_moduleHeader"

        'Content Panel
        Dim contentPanel As New Panel
        contentPanel.ID = Me.UniqueID & "_moduleContent"

        Dim headerImage As New Web.UI.WebControls.Image
        headerImage.ID = Me.UniqueID & "imgHeader"
        headerImage.ImageUrl = "~/images/expand_blue.jpg"

        'Add Content to header panel
        Dim aDiv As New LiteralControl
        aDiv.Text = "<div class=""cpeHeader"">"
        aDiv.Text &= "  <div class=""cpeHeaderTitle"">" & Title & "</div>"
        aDiv.Text &= "  <div class=""cpeHeaderDetails"">" & renderControlToString(aDetailLabel) & "</div>"
        aDiv.Text &= "  <div class=""cpeHeaderImage"">" & renderControlToString(headerImage) & "</div>"
        aDiv.Text &= "</div>"

        'Output header panel


        'Output Ajax functionality
        Dim collPanel As New AjaxControlToolkit.CollapsiblePanelExtender
        collPanel.ID = Me.UniqueID & "_cpeDemo"
        collPanel.TargetControlID = Me.UniqueID & "_moduleContent"
        collPanel.ExpandControlID = Me.UniqueID & "_moduleHeader"
        collPanel.CollapseControlID = Me.UniqueID & "_moduleHeader"
        collPanel.Collapsed = False
        collPanel.TextLabelID = Me.UniqueID & "_lblHeaderDetails"
        collPanel.ExpandedText = "(Hide Details...)"
        collPanel.CollapsedText = "(Show Details...)"
        collPanel.ImageControlID = "imgHeader"
        collPanel.ExpandedImage = "~/images/collapse_blue.jpg"
        collPanel.CollapsedImage = "~/images/expand_blue.jpg"
        collPanel.SuppressPostBack = True
        collPanel.Page = MyBase.Page

    End Sub

Thx for your help!

1/16/2007 10:34:26 AM 3498 articles. 0 followers. Follow

4 Replies

Similar Articles

[PageSpeed] 14
Get it on Google Play
Get it on Apple App Store

I case somebody should be looking for a solution for this, I solved my problem by adding the extendercontrol (and others) in the PreRender method using controls.add and in de render method I just render the header control and the base control


1/26/2007 1:58:57 PM

Hi Andres

I am having the same problem and I can't find the correct combination of control rendered in the PreRender and Render method. When I tried to render the header control and the base control in Render method I received an error detailing that controls specified in TargetControlID and ExpandControlID don't exist.

Could you send me the code of your PreRender and Render method?

 Thanks in advance,


2/21/2007 2:28:05 PM

Hi Leonardo

In the prerender I add all the controls.  The trick is to declare your controls as private members and not as variables inside your prerender method!

Private contentPanel As New Panel
 Private collPanel As New AjaxControlToolkit.CollapsiblePanelExtender
 Private aDetailLabel As New Label
 Private headerPanel As New Panel
 Private aDiv As New LiteralControl

    Protected Overrides Sub Render(ByVal output As HtmlTextWriter)


    End Sub

    Private Sub Ant_baseModule_PreRender(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.PreRender


    End Sub

    Private Sub createModuleItems()

        'Detail Label
        aDetailLabel.ID = Me.UniqueID & Me.IdSeparator & "lblHeaderDetails"
        aDetailLabel.Text = "(Show Details...)"

        'Collapse Image
        Dim imgCollapse As New UI.WebControls.Image
        imgCollapse.ID = Me.UniqueID & Me.IdSeparator & "collapseImage"

        'Header Panel
        headerPanel.ID = Me.UniqueID & Me.IdSeparator & "moduleHeader"

        'Add Content to header panel
        aDiv.Text = "<div class=""cpeHeader"">"
        aDiv.Text &= "  <div class=""cpeHeaderTitle"">" & Title & "</div>"
        aDiv.Text &= "  <div class=""cpeHeaderDetails"">" & renderControlToString(aDetailLabel) & "</div>"
        aDiv.Text &= "<div class=""cpeHeaderImage"">" & renderControlToString(imgCollapse) & "</div>"
        aDiv.Text &= "</div>"

        'Output Ajax functionality
        collPanel.ID = Me.UniqueID & Me.IdSeparator & "cpeDemo"
        collPanel.TargetControlID = Me.UniqueID
        collPanel.ExpandControlID = Me.UniqueID & Me.IdSeparator & "moduleHeader"
        collPanel.CollapseControlID = Me.UniqueID & Me.IdSeparator & "moduleHeader"
        collPanel.Collapsed = False
        collPanel.TextLabelID = Me.UniqueID & Me.IdSeparator & "lblHeaderDetails"
        collPanel.ExpandedText = "(Hide Details...)"
        collPanel.CollapsedText = "(Show Details...)"
        collPanel.ImageControlID = Me.UniqueID & Me.IdSeparator & "collapseImage"
        collPanel.ExpandedImage = "~/images/collapse_blue.jpg"
        collPanel.CollapsedImage = "~/images/expand_blue.jpg"
        collPanel.SuppressPostBack = True
        collPanel.Page = MyBase.Page

    End Sub

 I hope it helps to fix your problem!


2/21/2007 3:02:52 PM

Hi Andres

Yes, this helps me a lot!

I had two errors:

- I was overriding RenderControl instead of Render
- The controls were variables into prerender method

The webparts currently render all the controls except CollapsiblePanelExtender. I can't find the client code generated by the control.

I am trying to find where is the problem located, however, thanks so much for your help!



2/21/2007 7:52:34 PM

Similar Artilces:

Usercontrol vs Custom Server Controls, Any need for Custom Server Controls
Hello I'm new to ASP.Net so this is probably a stupid question but, is there any need to create customer server controls now that you can pre-compile usercontrols into a dll and thus easily share between applications? This blog post from David Ebb describes how to do it and the restrictions he note don't seem that bad (other than being able to embed resources such as images in the dll). His article desribes the techniques for ASP.Net 2.0 and he suggests that there will be further improvements in .Net 3.5 in this ar...

Custom Server Control Vs Web Parts, Any need for Custom Server Control
Hello I've just posted a similar question on why you need server controls when you can pre-compile usercontrols and redistribute them. I've seen lots of (usercontrol vs web part) but not much on web part vs custom server control. According to the MSDN site you can put web parts onto a normal page outside of a web part zone and they behave just like custom server controls. So, if you are creating a bunch of controls for redistribution to customer sites and/or SharePoint sites why don't you just create Web Par...

problems listenening to events on a custom server control from another custom server control
 Hi all,I am having problems listening to events on one of custom server controls(AddBookmark) from another custom server control(BookmarkList). The listener or the BookmarkList control has a property that can be set to the AddBookmark control (string at design but the reference is obtained at run-time). I am able to get a reference to the AddBookmark control and add a listener to it on the BookmarkList control on the OnPrender of BookmarkList. But the problem is that when the events on AddBookmark gets fired, the listener added from the BookmarkList is no longer present and the listene...

Custom Server Control Made of Custom Controls?
I'm giving myself a crash course in custom server controls, and I have a quick general question. Can I have a custom server control that is composed of other server controls I created. I'm pretty sure the answer is yes, but I want to be positive. Yes Shows how to combine existing controls into a new control using class composition. -ron Thanks! ASP.NET so rocks! Making page components extensible objects is such a great idea! I love it....

how to have both server controls and html controls rendered in a custom control?
I have a custom control in which there is an html text box.when you click on it , a div containing a table is appeared and according to what you select in that table a text is set to the text box. It works fine but the problem is: as the text box is an html element it doesn't have viewstate and when a post back occures in the page its value disappeares.I tried a hidden field to keep its value.again there is another problem : I put this custom control in a usercontrol and put the usercontrol in a multiview and by clicking on a button this view is selected and by clicking another bu...

Using a server control in the rendering a custom control
Hi. I have a custom control that overrides the Render method to draw itself.  Is it possible to use a server control (asp:Image, wwHoverPanel, etc.) inside such a custom control or would I have to rewrite my custom control as a composite control? I'd like to do something something like:protected override void Render(HtmlTextWriter w) { w.RenderBeginTag(HtmlTextWriterTag.Table); w.RenderBeginTag(HtmlTextWriterTag.Tr) w.RenderBeginTag(HtmlTextWriterTag.Td) // somehow place asp:Label here w.RenderEndTag(); // column w.RenderEndTag(); // row ...

Using a user control in a custom server control.
I've created a custom server control and am trying to add a user control to the rendering of the server control.  Is this possible?  If so, hints as to how this is done would be GREATLY appreciated!  Thanks in advance for considering an answer to this question. Wendi Use the LoadControl method. For example:   Controls.Add(LoadControl("~/controls/login.ascx"))Steven BeyRecursion: see Recursion My server control renders a table with x number of rows.  I want to add a user control to each row of the table, last column.  I do not know how ...

Help! Custom Server Control using User Control
I've been bashing my head for a few days on this problem. My Custom Server Control loads the User Control and renders it properly.  But, when I run the web application the controls (ex: buttons) from the User Control is not firing the event (ex: a button click to change the label's text)?Here is a snippet of part of my code:    Protected Overrides Sub CreateChildControls()        plhPanel = New System.Web.UI.WebControls.PlaceHolder        ContentFileLoaded = New System.Web.UI.U... controls used in custom composite controls?
I am creating an events calendar that uses the accordion to display the events for the selected day.  The problem I'm having is that the accordion is not responding to any client side events.  I would really like to find a good "How to" article for building composite controls that incorporate an control like the accordion....

Can we use existing Server Controls to create Custom Controls?
Can we use the existing ASP.Net Server Controls to create Custom Controls? I am able to use HtmlTextWriter to make my Custom Controls. I want to be able to add regular ASP.Net server controls to create my Custom Controls. Is this possible? Can anyone provide a sample? Basically, you just need to inherit the control you want to use, like this: Public Class MyControl Inherits System.Web.UI.WebControls.TextBox Then you can override the methods you want and add code as needed. Peter BrunoneMS MVP, ASP.NETFounder, EasyListBox.comDo the impossible, and go home early. The str...

Custom Server Control with Child Controls
I have a custom server control <xx.Parent... /> which parses custom child controls <xx.Child... />. In Visual Studio 2008, IntelliSense shows me both when I start typing my control namespace. How can I prevent the child control from showing up in IntelliSense  unless I'm adding it within the parent tags?Thanks. --Rudy...

Custom Server Control With Child Control
All, I am currently putting together a very simple control. The new control outputs a table with two rows. The top row contains a heading and the bottom row will contain any other content. The control as it stands works perfectly well and I can place text into the content row no problem. Now, to the problem. Once I'd completed the control I figured it would be neat to enable the developer to add controls directly into the bottom row (content row) of the outputted table. As you probably know the WebControl class has a Controls collection which the developer can use to add any other...

How do I use an embedded resource image in an imagebutton control in a custom server control?
I have a custom server control that I am building that includes an imagebutton control. I want to be able to use an image that I have included in the control as an embedded resource. Am I missing something here.... How do I get the imagecontrol to use the embedded resource image instead of the imageurl? Note : I'm still on 1. - not 2. yet....I build the the image control as follows.... Dim imgButton As New ImageButtonimgButton.ToolTip = Me.ToolTipimgButton.ImageUrl = ?????????AddHandler imgButton.Click, AddressOf imgButton_ClickControls.Add(imgButton)thanks I had the same question. Found ...

Custom Control within a Control Control
I am developing a custom controls that will render headers for different web sites. Within these controls, I want to place another custom control that will change the language. I created the language control and had it implement IPostBackDataHandler. This control works fine if I drag it on a new web form, but if I tell a header custom control to render it problems occur. The Language Selector custom control does not have a Page member anymore and the event handlers do not work. Does anyone have any experience with doing something similiar? Anyone have any suggestions? Thanks, ...

handling events for controls in custom server control
Hi,     I am having a problem in using server controls in ASP.Net, with C#.  I am trying to create a server control which contains 2 other server controls that I created (Called MyImageButton).  MyImageButton extends the standard ImageButton with some other properties & methods that I needed.  It therefore also has the 'OnClick' event.  From the original server control, I would like to handle the Click event for these 2 image buttons in the same server control.  Basically, this server control will show 2 images, ascending and descendin...

Adding controls to a Custom DataGrid Server Control
Edited by SomeNewKid. Please post code between <code> and </code> tags. I'm working on creating my own customized datagrid control. I've created a class which inherits "System.Web.UI.WebControls.DataGrid" and when I add my new datagrid control library to my project it seems to work nicely. Now I want to add some submit buttons to appear at the bottom of my datagrid control. How do I do this? Sorry, I'm a bit of a newbie at server controls. Here's what I've tried: Public Class UberDataGrid Inherits DataGrid Private MyButton As Button ...

How to render a repeater control in the custom server control?
 How to render a repeater control in the custom server  control because there is a lot of element inside the repeater control? My code is as follows: <div> <asp:Repeater ID="rptFields" runat="server"> <HeaderTemplate> <table> </HeaderTemplate> <ItemTemplate> <tr> <td><%# Eval("Prompt") %>:</td> <td><asp:PlaceHolder ID="plControl" runat="server" /> <input type="...

Custom Server Control to render multiple Controls
I have a need to build a reusable "Custom Server Control" that will in turn render multiple controls at runtime. The four controls I need it to render are as follows  <asp:Label ID="divLogin" runat="server" Text=" | " /> <asp:LoginStatus CssClass="footer" ID="LoginStatus1" runat="server" LogoutPageUrl="Default.aspx" /> <asp:Label ID="divAdmin" runat="server" Text=" | " /> <asp:HyperLink CssClass="footer" ID="btnAdmin" NavigateUrl=&...

load user control from server custom control
hi all,i have a 3rd party menu control that consists of a bunch of HyperLinks and a PlaceHolder control (C# v1.1.4) . links to .ascx files are retrieved from a data source, and when the page containing the control is loaded or a link clicked, the control uses this.Page.LoadControl(strLink) to add the .ascx to the PlaceHolder. fine and dandy, probably wouldnt have done it that way myself, but i'm stuck with it :)the problem is events: i can't raise 'em :( if i have for example a Button control on one of the .ascx pages, the Button.Click will go by unnoticed on the post-back. stran...

Target Control Attribute for custom server control
hi, i'm building a new custom control which is bindable to other custom controls which i have in my application.  my question is the following:i'm interested to have the same behavior that other Ajax control have with the "TargetControl" attribute. meaning that i can chose the target control that my custom control is  binded do i define this attribute (so i can use it through the html designer)?i hope this question is clear, if not, just this that i want to have the same behavior that Validators do with the "ControlToValidate" attribute/property. i want to create t...

Custom controls having Ajax Controls
I have a custom control called ModalUpdateProgress. I don't want to narrow down the topic to why do I have to build it or something else. The point of control is to lock a sceen while postback happens so it is a conjunction of Update Progress and Modal Popup Extender. I had no problem to build a control similar to Update Progress. Then I add Modal Popup Extender:   if(typeof(undefined) != typeof(AjaxControlToolkit)) if(typeof(undefined) != typeof(AjaxControlToolkit.ModalPopupBehavior)) { this._modalPopupBehavior = $create(AjaxControlToolkit.ModalPopup...

Custom Control within a Custom Control
I have two individual custom controls say custom cc1 and cc2. cc1 is communicating to cc2 using event delegate mechanism.I have tested the behaviour by dropping cc1 and cc2 onto a Web Page and it works fine. I want to create a third custom control say cc3 which should contain both cc1 and cc2. So that if i drag and drop cc3 onto a Web Page i can acheive exactly what i am doing above. The problem is that i am not sure how to call/register a custom control within a custom control ? Any clue ? Thanks!! Hi, Do you mean adding custom control to custom control? I think you can use the same wa...

Server Controls Within Server Controls
I'm a little new to server controls so this question may seem silly, but has anyone had trouble with events from custom server controls that are embedded in other custom server controls? I'm trying to create a composite control that creates a list of items and creates an instance of another composite control for each item. So for example the list could be a collection of addresses that has an editor composite control for each item. The editor composite control allows the user to edit the item and click on a save button. This works fine if it is on it's own (ie not part of the list ...

Server Control inside Server Control
I'm developing a server control that in turns contains another server control (i.e. Label). I instantiate the label and expose the entire Label through a property.   Imports System Imports System.Web Imports System.Web.UI Public Class Class1     Inherits Control       Dim _label As New WebControls.Label     Public Property L() As WebControls.Label         Get             Return _label         End Get ...

Web resources about - Using ajax control (CollapsiblePanelExtender) in custom server control -

Resources last updated: 2/18/2016 5:46:02 AM