need help with dynamically created user control

Discussion in 'ASP .Net' started by Karl Seguin, Aug 10, 2003.

  1. Karl Seguin

    Karl Seguin Guest

    i have a dynamically created user control which contains a non-dynamically
    created ASP.Net button. When the button is clicked, the event is not fired.
    I know that the control must be created on postback, and it is. However,
    I've noticed an intriguing thing which I think might be at the root of the
    problem.

    My page inherits from a basepage, which in turn inherits from
    System.Web.UI.Page. On initial load, the events fire something like this:

    page.load (aspx page)
    control.load (dynamically loaded ascx control)
    base.CreateChildControls (base page)
    base.Render (base page)

    however, on postback, the sequence of events changes to:
    base.CreateChildControls
    page.load
    control.load
    base.Render


    I imagine that this unexpected change of sequence, in addition to what I'm
    probably doing in CreateChildControls is the cause of my problem. I'm
    guessing this because if I make my page inherit directly from
    System.Web.UI.Page, the problem is solved (also, if I don't make the control
    dynamic, the problem is solved).

    Here's my CreateChildControls in the base page, as I suspect I might be
    doing something wrong in it:

    Protected Overrides Sub CreateChildControls()
    Me.Controls.Add(_plcContent)
    Dim mainForm As HtmlForm = CType(Page.FindControl("frmMain"), HtmlForm)
    If Not mainForm Is Nothing Then
    Dim Header As Control =
    CType(Page.LoadControl("~/Presentation/Header.ascx"), Control)
    Dim Footer As Control =
    CType(Page.LoadControl("~/Presentation/Footer.ascx"), Control)
    mainForm.Controls.AddAt(0, Header)
    mainForm.Controls.Add(Footer)
    _plcContent.Controls.Add(mainForm)
    End If
    MyBase.CreateChildControls()
    End Sub


    _plcContent is a new PlaceHolder defined in the base page.

    Karl
     
    Karl Seguin, Aug 10, 2003
    #1
    1. Advertising

  2. Karl, I am trying to Open my Mind.
    Should MyBase.CreateChildControls() be first in line??
    just guessing.

    "Karl Seguin" <karl @ openmymind.net> wrote in message
    news:...
    > i have a dynamically created user control which contains a non-dynamically
    > created ASP.Net button. When the button is clicked, the event is not

    fired.
    > I know that the control must be created on postback, and it is. However,
    > I've noticed an intriguing thing which I think might be at the root of the
    > problem.
    >
    > My page inherits from a basepage, which in turn inherits from
    > System.Web.UI.Page. On initial load, the events fire something like this:
    >
    > page.load (aspx page)
    > control.load (dynamically loaded ascx control)
    > base.CreateChildControls (base page)
    > base.Render (base page)
    >
    > however, on postback, the sequence of events changes to:
    > base.CreateChildControls
    > page.load
    > control.load
    > base.Render
    >
    >
    > I imagine that this unexpected change of sequence, in addition to what I'm
    > probably doing in CreateChildControls is the cause of my problem. I'm
    > guessing this because if I make my page inherit directly from
    > System.Web.UI.Page, the problem is solved (also, if I don't make the

    control
    > dynamic, the problem is solved).
    >
    > Here's my CreateChildControls in the base page, as I suspect I might be
    > doing something wrong in it:
    >
    > Protected Overrides Sub CreateChildControls()
    > Me.Controls.Add(_plcContent)
    > Dim mainForm As HtmlForm = CType(Page.FindControl("frmMain"),

    HtmlForm)
    > If Not mainForm Is Nothing Then
    > Dim Header As Control =
    > CType(Page.LoadControl("~/Presentation/Header.ascx"), Control)
    > Dim Footer As Control =
    > CType(Page.LoadControl("~/Presentation/Footer.ascx"), Control)
    > mainForm.Controls.AddAt(0, Header)
    > mainForm.Controls.Add(Footer)
    > _plcContent.Controls.Add(mainForm)
    > End If
    > MyBase.CreateChildControls()
    > End Sub
    >
    >
    > _plcContent is a new PlaceHolder defined in the base page.
    >
    > Karl
    >
    >
     
    MS News \(MS ILM\), Aug 10, 2003
    #2
    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. Duncan Welch
    Replies:
    2
    Views:
    416
    Duncan Welch
    Jul 2, 2003
  2. Atif Jalal
    Replies:
    0
    Views:
    444
    Atif Jalal
    May 26, 2004
  3. Gopal Krish
    Replies:
    2
    Views:
    3,059
    Gopal Krish
    Oct 8, 2004
  4. Replies:
    0
    Views:
    360
  5. msimmons
    Replies:
    0
    Views:
    498
    msimmons
    Jul 16, 2009
Loading...

Share This Page