LoadControl And Events Wireup

×

רמי

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
 
M

Manish

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
 
S

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

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,992
Messages
2,570,220
Members
46,807
Latest member
ryef

Latest Threads

Top