Persistance of Dynamicly added user controls.

M

Mike Housey

Can any one please tell me the best way to persist
dynamicly added user controls through page posts. I have
unsuccessfuly tried using the session object, but this
causes event firing to go haywire.

I set it up as follows:

I have created a web form(wf1.aspx) containing a panel and
1 user control(uc.ascx) containg a dropdown list and a
text box.

On the PageLoad Event of wf1:

if(!IsPostBack)
{
Control ctl = LoadControl("uc.ascx");
Panel1.Controls.Add(ctl);
Session["ctl"] = ctl;
}
else
{
Control ctl = (Control)Session["ctl"];
Panel1.Controls.Add(ctl);
}

A listbox on the custom control has a
selectedindex_changed event which fires once the first
time it is clicked, 2x the second, and 3x the third.
Obvioulsy one is not ment to store controls in the
Session. So how do I ?

Thanks in advance,

Mike Housey
 
K

Ken Cox [Microsoft MVP]

Denis Bauer of MS Germany has a couple of techniques on handling this with
viewstate:

http://www.denisbauer.com//ASPNETSamples.aspx

Ken

Can any one please tell me the best way to persist
dynamicly added user controls through page posts. I have
unsuccessfuly tried using the session object, but this
causes event firing to go haywire.

I set it up as follows:

I have created a web form(wf1.aspx) containing a panel and
1 user control(uc.ascx) containg a dropdown list and a
text box.

On the PageLoad Event of wf1:

if(!IsPostBack)
{
Control ctl = LoadControl("uc.ascx");
Panel1.Controls.Add(ctl);
Session["ctl"] = ctl;
}
else
{
Control ctl = (Control)Session["ctl"];
Panel1.Controls.Add(ctl);
}

A listbox on the custom control has a
selectedindex_changed event which fires once the first
time it is clicked, 2x the second, and 3x the third.
Obvioulsy one is not ment to store controls in the
Session. So how do I ?

Thanks in advance,

Mike Housey
 

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,743
Messages
2,569,478
Members
44,898
Latest member
BlairH7607

Latest Threads

Top