Child control forms data

Discussion in 'ASP .Net Building Controls' started by Johan Nordberg, Jan 20, 2004.

  1. I have made a custom template control which basically loads a web user
    control and replaces some PlaceHolders with content that I specify in
    the template control tag, like this:

    <J2:Host runat="server" id="TemplateHost"
    TemplateUrl="Templates/PageTemplate.ascx">
    <J2:Content Runat="server" ID="Header" AttachTo="Header" Text="My
    text"/>
    <J2:Content Runat="server" ID="Content" AttachTo="Content">
    This is my content
    </J2:Content>
    </J2:Host>

    This works excellent for just content, but I need to have form field
    in my content block as well. The problem is that when I post a form,
    the Page that contains the Template Control doesn't recognize the form
    fields as children of the page. Therefor event handlers for button
    doesn't work, view state is not restored and form field are not
    initialized with the posted value.

    How do I redirect all the posted data from an child control in my
    custom control, to the Page that hosts my control. I kind of would
    like all events from my control not handled by the control to bubble
    up to the page.

    Please help with some ideas!

    // Johan
    Johan Nordberg, Jan 20, 2004
    #1
    1. Advertising

  2. hi Johan, you need to override the onBubbleEvent method for your template
    and in turn override OnBubbleEvent for the container of your template which
    will expose the events to the page where your customControl sits. Look at
    some of the few last posts in the link below. This is a very recent
    discussion ;P
    http://groups.google.com/groups?hl=...io&hl=en&lr=&ie=UTF-8&oe=UTF-8&sa=G&scoring=d
    Post back if your still having problems ;)


    "Johan Nordberg" <> wrote in message
    news:...
    > I have made a custom template control which basically loads a web user
    > control and replaces some PlaceHolders with content that I specify in
    > the template control tag, like this:
    >
    > <J2:Host runat="server" id="TemplateHost"
    > TemplateUrl="Templates/PageTemplate.ascx">
    > <J2:Content Runat="server" ID="Header" AttachTo="Header" Text="My
    > text"/>
    > <J2:Content Runat="server" ID="Content" AttachTo="Content">
    > This is my content
    > </J2:Content>
    > </J2:Host>
    >
    > This works excellent for just content, but I need to have form field
    > in my content block as well. The problem is that when I post a form,
    > the Page that contains the Template Control doesn't recognize the form
    > fields as children of the page. Therefor event handlers for button
    > doesn't work, view state is not restored and form field are not
    > initialized with the posted value.
    >
    > How do I redirect all the posted data from an child control in my
    > custom control, to the Page that hosts my control. I kind of would
    > like all events from my control not handled by the control to bubble
    > up to the page.
    >
    > Please help with some ideas!
    >
    > // Johan
    Alessandro Zifiglio, Jan 20, 2004
    #2
    1. Advertising

  3. Thank you for replying.

    I solved it by my self. The problem was that I added the controls by overriding Render, which was too late. I changed my code to add child controls in OnInit instead and that made it all work just as I had thought it would

    However, event bubbling might still be interesting in other components

    // Johan
    Johan Nordberg, Jan 20, 2004
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Jeff Rodriguez
    Replies:
    23
    Views:
    1,111
    David Schwartz
    Dec 9, 2003
  2. caldera

    Placeholder child of child control event problem.

    caldera, May 27, 2004, in forum: ASP .Net Building Controls
    Replies:
    1
    Views:
    212
  3. Replies:
    0
    Views:
    206
  4. Eric
    Replies:
    2
    Views:
    480
  5. Jason Carlton
    Replies:
    4
    Views:
    161
    Thomas 'PointedEars' Lahn
    Dec 16, 2009
Loading...

Share This Page