471,570 Members | 927 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

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

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 3102

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

protected override void OnInit(EventArgs e)
{
btnGo=new Button();
btnGo.ID="btnGo";
btnGo.Text="Go";
btnGo.CssClass="Button";
this.Controls.Add(btnGo);

this.btnGo.Click += new System.EventHandler(this.btnGo_Click);
base.OnInit (e);
}
<co*******@gmail.com> wrote in message
news:11**********************@g43g2000cwa.googlegr oups.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.Add(user);
user.Click += new System.EventHandler(this.user_Click);

and then, somewhere in your code:

private void user_Click(object sender, System.EventArgs e)
{
... do whatever you want when the butotn is clicked ...
}

Dec 29 '05 #7

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by Kjell Kristiansson | last post: by
reply views Thread by Demetri | last post: by
4 posts views Thread by =?Utf-8?B?TWFyaw==?= | last post: by
reply views Thread by Vinnie | last post: by
reply views Thread by lumer26 | last post: by
reply views Thread by lumer26 | last post: by

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.