473,661 Members | 2,465 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to add click event for dynamically created User control page?

Hi all

Can anyone tell me how to add a click event for a user control page
dynamically???
Thanx
Krish.

Dec 27 '05 #1
6 3202

I use below code to add a dynamically control and += an event for it
override the OnInit event

protected override void OnInit(EventArg s e)
{
btnGo=new Button();
btnGo.ID="btnGo ";
btnGo.Text="Go" ;
btnGo.CssClass= "Button";
this.Controls.A dd(btnGo);

this.btnGo.Clic k += new System.EventHan dler(this.btnGo _Click);
base.OnInit (e);
}
<co*******@gmai l.com> wrote in message
news:11******** **************@ g43g2000cwa.goo glegroups.com.. .
Hi all

Can anyone tell me how to add a click event for a user control page
dynamically???
Thanx
Krish.

Dec 27 '05 #2
Dear Seraph Jiang ,

I should not create and use the button in my
appln.If i click anywhere in the User control ,it ll do something.The
user control contains 4 labels only... Now plz tell me is any other way
(without button creation) to do this task??

Thanx
Krish.

Dec 28 '05 #3
So, if I understand you, you want to respond to the "Click" event of
the UserControl itself.

If that's so, Seraph just showed you how to do it for a dynamically
created button. Just do exactly the same thing, substituting your
UserControl for Seraph's Button.

If I misunderstand, then maybe you could post the code to your
UserControl and explain in more detail what it is you want to do.

Dec 28 '05 #4
Dera Bruce,

Yes, I want to respond to the Click event of the UserControl
itself.If I click on the User Control it ll do some action...Plz tell
me How to do??

Dec 28 '05 #5
Dear Bruce,

Yes, I want to respond to the Click event of the UserControl
itself.If I click on the User Control it ll do some action...Plz tell
me How to do??

Dec 28 '05 #6
Well, just do exactly what Seraph showed you, but with your
UserControl:

MyUserControl user = new MyUserControl() ;
user.ID="user";
this.Controls.A dd(user);
user.Click += new System.EventHan dler(this.user_ Click);

and then, somewhere in your code:

private void user_Click(obje ct sender, System.EventArg s e)
{
... do whatever you want when the butotn is clicked ...
}

Dec 29 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
8156
by: Earl Teigrob | last post by:
PROBLEM: When a user control is loaded into a PlaceHolder control more than once, the events do not fire on the first click of a control on the dynamically loaded user control. In other words, the first time the control is dynamically loaded, everything works fine. After that, if the control is loaded again from the page button event handler, the user controls events fail to fire on the first click NOTE: I (believe I) am rebuilding all...
7
2295
by: Diane | last post by:
Hi- I've been struggling with this problem and none of the fixes posted seem to help out at all. Yet, it seems like such a simple problem... I have a DataGrid, and load it up with data on page load. In my EditCommand event handler I set the editItemindex. All good. Except, the user needs to click twice to get the DataGrid to become editable. It's obvious to me (perhaps worngly) that ASP.NET is storing the data
2
1318
by: Kjell Kristiansson | last post by:
I have not been able to figure out how to catch the click event from a button that is added dynamically to a table. In priciple the process is as follows: When I first create the page I analyse data and if appropriate: - add one or more row to a table in the webform - add cells to the rows - add a button (myButton) where the user can change some settings. - enable/disable some other buttons to the form This is all done in a function...
0
1412
by: conckrish | last post by:
Hi all, Can anyone tell me how to add Click event for dynamically created User control page ?? I have a user control page in datagrid cell. when i click this user control page it ll redirect to another page. plz tell me how to add click event ??? Thanx.
6
2851
by: hlubocky | last post by:
I thought I had a good grasp of the problem related to dynamically creating controls, but it appears that as my application grew in complexity, the problem has resurfaced. As I understand it, in order for a dynamically created control to persist its state, it needs to be created and loaded into the page control hierarchy before the viewstate is loaded. The proposed solution, and that which I have been using, has been to create all of...
0
2946
by: Demetri | last post by:
I have created a web control that can be rendered as either a linkbutton or a button. It is a ConfirmButton control that allows a developer to force a user to confirm if they intended to click it such as when they do a delete. Everything is great. By and large it will be used in my repeater controls using the command event when the user clicks on it and so that event is working great. My issue is the Click event. When the control is...
4
8456
by: Bob | last post by:
Hi, I'm working with VWD and i defined programmatically a button (in code-behind) with an ID. So I expect to see beside "Page Events" and "Form1" my button "b1" in order to use the Click event. But it doesnt' appear. After saving the code-behind file, i only see "Page Events" and "Form1". If i define the button declarativally, i see it. But i need to define it programmatically. Can anybody tell me how to do? I also tried with...
5
6755
by: Amoril | last post by:
I've read quite a few different message on various boards and for some reason I'm still having trouble wrapping my head around this viewstate maintenance and trying to get these dynamically created link buttons to stay wired up to their click events. I have what is basically a simply survey question generation page. The page first displays a few static fields and a dropdownlist of various options for the user to select. When the user...
4
2523
by: =?Utf-8?B?TWFyaw==?= | last post by:
Hi, I have built a custom control button which inherits from WebControl and implements IPostBackEventHandler. The control also declares an event Click and provides a method OnClick which invokes the registered delegate. All is fine with my control until I try to add it to the page dynamically in a code behind event handler and wire-up the click event using the normal syntax such that; protected void btnNew_Click(object sender, EventArgs...
0
8428
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8341
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
8851
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
8630
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
5650
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4177
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
4343
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
1984
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1740
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.