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

Experts: dynamic control events???

P: n/a
Hi all.

In response to user selections, our app adds controls (buttons, image
buttons) dynamically to a page with Controls.Add(myNewButtonControl).

Now that we gotten on the page we want to make them do something for a
living: how do we dynamically create events that the controls respond to?

TEA for any pointers.

- Assaf

Nov 18 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
Assaf hi,

You need to attach methods on your page to controls events. if you using
C# :
MyControl.Click += new EventHandler(FunctionNameWithDelegartionSign(;

VB:

AddHandlerMyControl.Click , AddressOf FunctionNameWithDelegartionSign

BUT! Event handler for dynamic control should be added before the page
finish to build controls. in the page life cycle the Load event is the
one that you can use.

Natty Gur[MVP]

blog : http://weblogs.asp.net/ngur
Mobile: +972-(0)58-888377
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 18 '05 #2

P: n/a
Thanks a bunch Bin Song.

One of the articles you listed revealed the missing part of the puzzle: I
couldn't get the events for the dynamic control (which by the way is a
custom composite control) to fire. What was missing was impmenting the
System.Web.UI.INamingContainer interface on the control.

- Assaf

"Bin Song, MCP" <an*******@discussions.microsoft.com> wrote in message
news:78**********************************@microsof t.com...
Hi,

If you know the object type and name, see this:
http://support.microsoft.com/default...b;en-us;317515
HOW TO: Dynamically Create Controls in ASP.NET with Visual Basic .NET
If Not,
http://support.microsoft.com/default...b;en-us;311321
HOW TO: Dynamically Add a Control Without Hardcoding the Control Type in Visual Basic .NET
Bin Song, MCP

Nov 18 '05 #3

P: n/a
Thanks for the pointer, Natty Guru.

I think I accidentally bypassed the problem by implementing the dynamically
added controls as custom composite controls. That way all the functionality
is baked into the composite control's inner controls (e.g., the button
control in the MyCustomCompositeControl control). I had to implement custom
composites for other reason, of course, not just to get around this problem.

- Assaf
"Natty Gur" <na***@dao2com.com> wrote in message
news:%2******************@TK2MSFTNGP12.phx.gbl...
Assaf hi,

You need to attach methods on your page to controls events. if you using
C# :
MyControl.Click += new EventHandler(FunctionNameWithDelegartionSign(;

VB:

AddHandlerMyControl.Click , AddressOf FunctionNameWithDelegartionSign

BUT! Event handler for dynamic control should be added before the page
finish to build controls. in the page life cycle the Load event is the
one that you can use.

Natty Gur[MVP]

blog : http://weblogs.asp.net/ngur
Mobile: +972-(0)58-888377
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!

Nov 18 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.