Dynamically added controls and events

P

Paul

An early Happy Thanksgiving to you and yours...

We develop data driven apps. We dynamically place controls on a panel which
may be then be placed on a web form or another control. My problem is that I
can't get the events of the hosted controls to fire.

e.g.
' myUserControl.ascx. is placed on myWebForm.aspx in the Designer
' myUserControl.ascx has a Panel on it, Panel1
' From code in myUserControl.ascx I pass Panel1 ByRef to a class with a
public sub which adds controls and events to the panel based on it's unique
identifier

When myWebForms.aspx presents the events will not fire. How can I accomplish
this? TIA
 
J

John M Deal

In order to get the events for dynamically added controls, you need to
make sure they are added to the form in the exact same order on every
post back. This means if you add a control, then remove it, then add
another, you will have to do that exact same sequence again the next
time the page is built.

Last night someone posted a link to this:

http://www.denisbauer.com/ASPNETControls/DynamicControlsPlaceholder.aspx

This looks to simplify the issues involved with dynamic controls and
their events by providing a control that handles it all for you. Look
into it, it looks pretty good (though I haven't tried it yet).

Have A Better One!

John M Deal, MCP
Necessity Software
 

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

No members online now.

Forum statistics

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

Latest Threads

Top