473,386 Members | 1,819 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

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 2107
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Quimbly | last post by:
My KeyDown / KeyUp / KeyPress events are not firing; I can't figure out what I'm doing wrong. The code I'm using is basically straight from the manual. "this" refers to my Windows.Forms.Form...
2
by: sunil | last post by:
Will the state of a dynamically loaded control preserved in transitions between aspx pages hosting the control.? thanks
0
by: Greg Park | last post by:
I have many user controls loading into a web page using Page.LoadControl However, I'm unable to figure out how to raise an event when a button is click or a check box is checked. I can have...
3
by: Robert Walter | last post by:
I want to user the Page method LoadControl inside the Global.asax.cs but when I instantiate a page and try it I get the following error... System.NullReferenceException: Object reference not set...
1
by: Nikolaj | last post by:
I'm loading a user control using the method: uc = Page.LoadControl("../UC.ascx"); Afterwards I set some variables in uc. For instance uc.Count = 10; Count is the number of link buttons...
0
by: Leszek Taratuta | last post by:
Hello, I load a user control using Page.LoadControl(). The user control contains two web controls: a drop-down list and a text box. The problem is that the SelectedItem as well as Text...
8
by: Sam Kuehn | last post by:
How do I accomplish the fallowing (is it even possible). Say I write a UserControl "MyControl.ascx". Now I use LoadControl("MyControl.ascx"). But I really want MyControl to require parameters in...
0
by: Carl Wright | last post by:
Hi I'm having this major issue loading a usercontrol at runtime using the overload on Loadcontrol(type,object). Here's the code in the aspx code-behind file Dim myControl As New Control Dim...
5
by: Paul King | last post by:
Hello, experts: I have a beginner's question. I would like to know if there is a sensible way of writing event handlers under VB. For a Numeric Update control called "nudSpin", this is...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.