LoadControl And Events Wireup

  • Thread starter Thread starter רמי
  • Start date Start date
×

רמי

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
 
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
 
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












- 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
 
Back
Top