Experts: dynamic control events???

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
 
N

Natty Gur

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
 
A

Assaf

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
 
A

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top