468,272 Members | 1,999 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,272 developers. It's quick & easy.

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
Jun 27 '08 #1
2 1964
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
Jun 27 '08 #2
On May 16, 1:28*pm, Manish <Man...@discussions.microsoft.comwrote:
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
Jun 27 '08 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by Quimbly | last post: by
2 posts views Thread by sunil | last post: by
3 posts views Thread by Robert Walter | last post: by
1 post views Thread by Nikolaj | last post: by
reply views Thread by Leszek Taratuta | last post: by
8 posts views Thread by Sam Kuehn | last post: by
reply views Thread by Carl Wright | last post: by
reply views Thread by NPC403 | last post: by
reply views Thread by zattat | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.