By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
444,168 Members | 2,599 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 444,168 IT Pros & Developers. It's quick & easy.

Attaching an event handler

P: n/a
I am creating a LinkLabel control at runtime. How do I attach an event
handler to it?

Where's the delegate for the OnClick event? I see an OnLinkClicked
delegate but since it is protected, it won't let me set it to the
address of my own handler.

Do I have to inherit every control just because I want to create it
dynamically at runtime?

Bottomline: If I've created a control at runtime, how do I attach my
own event handler to it. I mean, I know the syntax but I see that the
delegates are all "protected."

Nov 21 '05 #1
Share this Question
Share on Google+
5 Replies


P: n/a
"Water Cooler v2" <wt*****@yahoo.com> schrieb;
I am creating a LinkLabel control at runtime. How do I attach an event
handler to it?


Take a look at the 'AddHandler' statement.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>
Nov 21 '05 #2

P: n/a
oh yeah! I completely forgot. Thanks.

Nov 21 '05 #3

P: n/a
ok, how out of curiosity. If this was C# I was coding in, there's no
AddHandler there, so I believe the only way to do it would be to pass
the name (which is actually the address) of my own handler to the
delegate instancen member inside the control class. Since all these
delegate instance members are protected, would there have been a way to
do it in C# that did not involve inheriting from the control?

Nov 21 '05 #4

P: n/a
"Water Cooler v2" <wt*****@yahoo.com> schrieb:
ok, how out of curiosity. If this was C# I was coding in, there's no
AddHandler there, so I believe the only way to do it would be to pass
the name (which is actually the address) of my own handler to the
delegate instancen member inside the control class. Since all these
delegate instance members are protected, would there have been a way to
do it in C# that did not involve inheriting from the control?


You don't need to inherit in order to be able to add a handler.

\\\
this.Button1.Click += new System.EventHandler(this.Button1_Click);
///

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>
Nov 21 '05 #5

P: n/a
Water Cooler v2 wrote:
I am creating a LinkLabel control at runtime. How do I attach an event
handler to it?
Use the AddHandler statement

Where's the delegate for the OnClick event? I see an OnLinkClicked
delegate but since it is protected, it won't let me set it to the
address of my own handler.


If you are creating the control at runtime, you need to attach to the
LinkClicked event, not OnLinkClicked.

Nov 21 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.