Referencing Dynamically created controls

C

Chris Kennedy

Can anyone tell me how to reference a a control, e.g. a control I have added
to the controls collection without specifically naming it. Also can anyone
give me some pointer on how to attach events to them. Regards.
 
C

ccallen

See my reply in "Re: Dynamicly loaded User Control events in a Placeholder"

Search MSDN for EventHandler to get a listing of info & samples.

/*
* #C snippet showing how to create a user control & add an event handler
* CWebUserControl1 has an event called Alerted, the aspx defines a function
called Alerted2.
* Note the use of += when setting the EvnetHandler.
* The WebUserControl's classname "CWebUserControl1" is set in the ascx file
using the ClassName parameter of the @Control directive
* <%@Control language="C#" ClassName="CWebUserControl1"%>
*/

public void Page_Load(Object sender, EventArgs e) {

CWebUserControl1 ctl = new CWebUserControl1();
ctl = (CWebUserControl1) LoadControl ("WebUserControl1.ascx");
ctl.Alerted += new EventHandler(this.onAlerted2);
ph1.Controls.Add (ctl);

return;
}

ccallen
 

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