LoadControl And Events Wireup

Discussion in 'ASP .Net' started by רמי, May 14, 2008.

  1. Hey,
    I'm loading a webusercontrol dynamically using The following code:

    Control newCtrl = LoadControl("MyCtrl.ascx");
    newCtrl.ID = "MyCONTROL";
    container.Control.Add(newCtrl);

    My webusercontrol has a server-side button and it I implemented its
    OnClick event.

    On the Init event of the Page, I re add the control on each post back.

    And yet while pressing the button does postback, it doesn't wire my
    events and the OnClick is never executed.

    What am I missing?!

    Thanks ahead

    --sternr
     
    רמי, May 14, 2008
    #1
    1. Advertising

  2. רמי

    Manish Guest

    Hi,

    I am not able to replicate the issue. I tried the following code and it
    worked.

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As
    System.EventArgs) Handles Me.Load
    Dim control As UserControl =
    CType(LoadControl("~/WebUserControl.ascx"), UserControl)
    Me.form1.Controls.Add(control)
    End Sub

    In wEbuserControl.ascx,

    I have put the button control.

    Protected Sub Button1_Click(ByVal sender As Object, ByVal e As
    System.EventArgs) Handles Button1.Click
    Response.Write("test")
    End Sub

    Regards,
    Manish
    www.componentone.com


    "רמי" wrote:

    > Hey,
    > I'm loading a webusercontrol dynamically using The following code:
    >
    > Control newCtrl = LoadControl("MyCtrl.ascx");
    > newCtrl.ID = "MyCONTROL";
    > container.Control.Add(newCtrl);
    >
    > My webusercontrol has a server-side button and it I implemented its
    > OnClick event.
    >
    > On the Init event of the Page, I re add the control on each post back.
    >
    > And yet while pressing the button does postback, it doesn't wire my
    > events and the OnClick is never executed.
    >
    > What am I missing?!
    >
    > Thanks ahead
    >
    > --sternr
    >
     
    Manish, May 16, 2008
    #2
    1. Advertising

  3. רמי

    sternr Guest

    On May 16, 1:28 pm, Manish <> wrote:
    > Hi,
    >
    > I am not able to replicate the issue. I tried the following code and it
    > worked.
    >
    >  Protected Sub Page_Load(ByVal sender As Object, ByVal e As
    > System.EventArgs) Handles Me.Load
    >         Dim control As UserControl =
    > CType(LoadControl("~/WebUserControl.ascx"), UserControl)
    >         Me.form1.Controls.Add(control)
    >     End Sub
    >
    > In wEbuserControl.ascx,
    >
    > I have put the button control.
    >
    > Protected Sub Button1_Click(ByVal sender As Object, ByVal e As
    > System.EventArgs) Handles Button1.Click
    >         Response.Write("test")
    >     End Sub
    >
    > Regards,
    > Manishwww.componentone.com
    >
    >
    >
    > "רמי" wrote:
    > > Hey,
    > > I'm loading a webusercontrol dynamically using The following code:

    >
    > > Control newCtrl = LoadControl("MyCtrl.ascx");
    > > newCtrl.ID = "MyCONTROL";
    > > container.Control.Add(newCtrl);

    >
    > > My webusercontrol has a server-side button and it I implemented its
    > > OnClick event.

    >
    > > On the Init event of the Page, I re add the control on each post back.

    >
    > > And yet while pressing the button does postback, it doesn't wire my
    > > events and the OnClick is never executed.

    >
    > > What am I missing?!

    >
    > > Thanks ahead

    >
    > > --sternr- Hide quoted text -

    >
    > - Show quoted text -


    Hey,
    Yeah it turns out its because of my UpdatePanel - my dynamic
    webusercontrol is added as a child of the UpdatePanel...
    Do you have any idea why the UpdatePanel breaks the event wireup?
    Thanks ahead

    --sternr
     
    sternr, May 16, 2008
    #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. Jonel Rienton
    Replies:
    2
    Views:
    4,883
    Jonel Rienton
    Nov 24, 2003
  2. localhost

    Dynamic Control Event Wireup?

    localhost, May 14, 2004, in forum: ASP .Net
    Replies:
    3
    Views:
    10,290
    Steven Cheng[MSFT]
    May 19, 2004
  3. =?Utf-8?B?Tmlrb2xhag==?=

    events, prerender and LoadControl()

    =?Utf-8?B?Tmlrb2xhag==?=, Sep 27, 2004, in forum: ASP .Net
    Replies:
    1
    Views:
    757
    Karl Seguin
    Sep 27, 2004
  4. =?Utf-8?B?T2RkYmFsbA==?=

    Event wireup headache

    =?Utf-8?B?T2RkYmFsbA==?=, Oct 2, 2006, in forum: ASP .Net
    Replies:
    1
    Views:
    400
    bruce barker \(sqlwork.com\)
    Oct 2, 2006
  5. =?Utf-8?B?dGVkMTIz?=

    wireup Page_Load programmatically in ASP.NET 2.0

    =?Utf-8?B?dGVkMTIz?=, May 9, 2007, in forum: ASP .Net
    Replies:
    2
    Views:
    1,170
    Mark Rae
    May 9, 2007
Loading...

Share This Page