Using Ajax control in custom server control

M

MrFraggle

Hi

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"

'Image
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>"
headerPanel.Controls.Add(aDiv)

'Output header panel
output.Write(renderControlToString(headerPanel))

contentPanel.RenderBeginTag(output)
MyBase.Render(output)
contentPanel.RenderEndTag(output)

'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
collPanel.RenderControl(output)

End Sub

Thx for your help!
 
M

MrFraggle

Hi thx for your reply. But I have the directive on the page...

I tried out some more things, I moved some stuff to the prerender and I
also added this line to that function:
CType(MyBase.Page.FindControl("ScriptManager1"),
System.Web.UI.ScriptManager).RegisterExtenderControl(collPanel,
contentPanel)

Now I don't have the error anymore but the collapse isn't working.
When I take a look at the rendered HTML I see that some javascript is
missing. When I look in the generated HTML of the Sample Collapsible
panel there is a line:

Sys.Application.add_init(function() {
$create(AjaxControlToolkit.CollapsiblePanelBehavior,
{"ClientStateFieldID":"ctl00_SampleContent_cpeDemo_ClientState","CollapseControlID":"ctl00_SampleContent_Panel2","Collapsed":true,"CollapsedImage":"../images/expand_blue.jpg","CollapsedText":"(Show
Details...)","ExpandControlID":"ctl00_SampleContent_Panel2","ExpandedImage":"../images/collapse_blue.jpg","ExpandedText":"(Hide
Details...)","ImageControlID":"ctl00_SampleContent_Image1","SuppressPostBack":true,"TextLabelID":"ctl00_SampleContent_Label1","id":"ctl00_SampleContent_cpeDemo"},
null, null, $get("ctl00_SampleContent_Panel1"));
});

But my control doesn't generate this line. How can I cause my control
to also generate this line?
 
M

MrFraggle

Ok, I found it, it was pretty simple :s Instead of rendering the
controls you just have to use:
Controls.Add()

It's working perfect now!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,228
Members
46,818
Latest member
SapanaCarpetStudio

Latest Threads

Top