Retaning state of Dynamically Created Controls in ASP.NET.

  • Thread starter Thread starter aroraamit81
  • Start date Start date
A

aroraamit81

How do I retain State for Dynamically Created Controls in ASP.NET.
I have created a control on first time page load, but when I do post
back, then my dynamic controls gets disappeared. I have used code like
this:

CheckBox chkbox=new CheckBox();
chkbox.ID="chkcontact"+objread2["contact_id"].ToString();

chkbox.AutoPostBack=true;
chkbox.EnableViewState=true;

Any clues????

Regards,
Amit Arora
 
Hi Amit,

You'll need to recreate the control every time the page is loaded, not
just when Page.IsPostBack is true. It should keep its state through
the ViewState.

HTH,
Chris
 
Yup, thats something we are doing, but it some how slows down my page's
performance so I wanted to retain the values.

Any clues???
 
If you know the dynamically generated ID, you can use Request["id"], I
think. That is, if you just want to obtain the value. If you want to
retain the controls, you have to create them again.


Regards,
Jim
 
Back
Top