473,765 Members | 2,203 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

LoadControl And Events Wireup

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

Control newCtrl = LoadControl("My Ctrl.ascx");
newCtrl.ID = "MyCONTROL" ;
container.Contr ol.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 2125
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.EventArg s) Handles Me.Load
Dim control As UserControl =
CType(LoadContr ol("~/WebUserControl. ascx"), UserControl)
Me.form1.Contro ls.Add(control)
End Sub

In wEbuserControl. ascx,

I have put the button control.

Protected Sub Button1_Click(B yVal sender As Object, ByVal e As
System.EventArg s) 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("My Ctrl.ascx");
newCtrl.ID = "MyCONTROL" ;
container.Contr ol.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...@discuss ions.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.EventArg s) Handles Me.Load
Â* Â* Â* Â* Dim control As UserControl =
CType(LoadContr ol("~/WebUserControl. ascx"), UserControl)
Â* Â* Â* Â* Me.form1.Contro ls.Add(control)
Â* Â* End Sub

In wEbuserControl. ascx,

I have put the button control.

Protected Sub Button1_Click(B yVal sender As Object, ByVal e As
System.EventArg s) Handles Button1.Click
Â* Â* Â* Â* Response.Write( "test")
Â* Â* End Sub

Regards,
Manishwww.compo nentone.com

"רמי" wrote:
Hey,
I'm loading a webusercontrol dynamically using The following code:
Control newCtrl = LoadControl("My Ctrl.ascx");
newCtrl.ID = "MyCONTROL" ;
container.Contr ol.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
6309
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 object. this.KeyDown += new System.Windows.Forms.KeyEventHandler(this.MainForm_KeyDown); this.KeyPress += new
2
1480
by: sunil | last post by:
Will the state of a dynamically loaded control preserved in transitions between aspx pages hosting the control.? thanks
0
1724
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 upto a hundred user controls on a single page and AutoPostBack isn't an option. I have no problem with raising events when an user control is dropped on the aspx page.
3
3017
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 to an instance of an object. at System.Web.UI.UserControlParser.GetCompiledUserControlType(String virtualPath, String inputFile, HttpContext context) at System.Web.UI.TemplateControl.LoadControl(String virtualPath) at...
1
5842
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 which should be generated in uc. The Pre_Render method of uc looks like this:
0
1311
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 properties are not available in Page_Load of the user control when the page is posted back. The properties are simply empty strings. They become availlable in PostBack events such as Button_Click or Page_PreRender, but I need these values during Page_Load.
8
5247
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 the constructor for example MyContorl oMyControl = new MyContorl(employeeid). However I need to load the control at runtime so the have to call it this way LoadControl("MyControl.ascx") and I get an error that I have not supplied any parameter...
0
3784
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 strCtlPath As String = "~/includes/pinned/NewConsumerReviews.ascx" Dim objParams(0) As Object objParams(0) = 1
5
1899
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 apparently wrong: Private Sub nudSpin_MouseUp() Handles nudSpin.MouseUp ' my code End Sub
0
9398
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10156
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10007
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
7375
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5275
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5419
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3924
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3531
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2805
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.