Experts: dynamic control events???

  • Thread starter Thread starter Assaf
  • Start date Start date
A

Assaf

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
 
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
 
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
 
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
 
Back
Top