need help with dynamically created user control

Ask a Question related to ASP.NET General, Design and Development.

  1. #1

    Default need help with dynamically created user control

    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 Guest

  2. Similar Questions and Discussions

    1. Managing ViewState of a dynamically created Custom Composite Server Control -(where the original is also dynamically created)
      Ok here's my scenario. I have a Custom Composite Server Control (CCSC) consisting of a TextBox, Button & Panel. (And some other code - which I...
    2. Dynamically created user controls
      In ASP.Net, I am working with some in-house software that dynamically creates a form based on rows in a database table. For example, most pages...
    3. Retrieving Values from dynamically created controls in a user control
      Hi, Dynamic control should be load every time page load, even on post back. take out control creation from IsPostBack condition. Natty Gur ...
    4. dynamically created control is not being validated
      I have a user control that contains a custom control, both are loaded dynamically. The custom control has a simple required field validator and a...
    5. returning values from dynamically created user control
      Hi, I've got a fairly simple date control, that I'm creating dynamically in my page. The reason for creating it dynamically is that I want the...
  3. #2

    Default Re: need help with dynamically created user control

    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:u1zI6G1XDHA.736@TK2MSFTNGP09.phx.gbl...
    > 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\) Guest

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139