Home All Groups Group Topic Archive Search About

Using Ajax control in custom server control

Author
20 Jan 2007 12:02 PM
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!

Author
22 Jan 2007 7:47 PM
Steve C. Orr [MCSD, MVP, CSM, ASP Insider]
The page needs a directive for extender control.
Alternately it can be set globally in the web.config.

Here are more details:
http://weblogs.asp.net/scottgu/archive/2006/11/26/tip-trick-how-to-register-user-controls-and-custom-controls-in-web-config.aspx

--
I hope this helps,
Steve C. Orr,
MCSD, MVP, CSM, ASPInsider
http://SteveOrr.net



Show quoteHide quote
"MrFraggle" <mrfrag***@gmail.com> wrote in message
news:1169294551.687331.200150@s34g2000cwa.googlegroups.com...
> 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!
>
Author
25 Jan 2007 9:57 AM
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?




On 22 jan, 20:47, "Steve C. Orr [MCSD, MVP, CSM, ASP Insider]"
<S***@Orr.net> wrote:
Show quoteHide quote
> The page needs a directive forextendercontrol.
> Alternately it can be set globally in the web.config.
>
> Here are more details:http://weblogs.asp.net/scottgu/archive/2006/11/26/tip-trick-how-to-re...
>
> --
> I hope this helps,
> Steve C. Orr,
> MCSD, MVP, CSM, ASPInsiderhttp://SteveOrr.net
>
> "MrFraggle" <mrfrag***@gmail.com> wrote in messagenews:1169294551.687331.200***@s34g2000cwa.googlegroups.com...
>
>
>
> > Hi
>
> > I'm trying to write a servercontrolthat contains the
> > collapsiblePanelExtender from the ajax toolkit.  But I have the
> > following error when i try to show thiscontrol:
>
> >Extendercontrol'ctl00$contentHolder$ctl00$Ant_baseModule1_cpeDemo' is
> >notaregisteredextendercontrol.Extendercontrolsmustberegistered
> >usingRegisterExtenderControl() before calling
> > RegisterScriptDescriptors().
>
> > I have no idea what imustadd 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!- Tekst uit oorspronkelijk bericht niet weergeven -- Tekst uit oorspronkelijk bericht weergeven -
Author
25 Jan 2007 10:59 AM
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!



Show quoteHide quote
On 25 jan, 10:57, "MrFraggle" <mrfrag***@gmail.com> wrote:
> 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","CollapseCo­ntrolID":"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","SuppressPostBac­k":true,"TextLabelID":"ctl00_SampleContent_Label1","id":"ctl00_SampleConten­t_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?
>
> On 22 jan, 20:47, "Steve C. Orr [MCSD, MVP, CSM, ASP Insider]"
>
>
>
> <S***@Orr.net> wrote:
> > The page needs a directive forextendercontrol.
> > Alternately it can be set globally in the web.config.
>
> > Here are more details:http://weblogs.asp.net/scottgu/archive/2006/11/26/tip-trick-how-to-re...
>
> > --
> > I hope this helps,
> > Steve C. Orr,
> > MCSD, MVP, CSM, ASPInsiderhttp://SteveOrr.net
>
> > "MrFraggle" <mrfrag***@gmail.com> wrote in messagenews:1169294551.687331.200***@s34g2000cwa.googlegroups.com...
>
> > > Hi
>
> > > I'm trying to write a servercontrolthat contains the
> > > collapsiblePanelExtender from the ajax toolkit.  But I have the
> > > following error when i try to show thiscontrol:
>
> > >Extendercontrol'ctl00$contentHolder$ctl00$Ant_baseModule1_cpeDemo' is
> > >notaregisteredextendercontrol.Extendercontrolsmustberegistered
> > >usingRegisterExtenderControl() before calling
> > > RegisterScriptDescriptors().
>
> > > I have no idea what imustadd 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!- Tekst uit oorspronkelijk bericht niet weergeven -- Tekst uit oorspronkelijk bericht weergeven -- Tekst uit oorspronkelijk bericht niet weergeven -- Tekst uit oorspronkelijk bericht weergeven -