Retaning state of Dynamically Created Controls in ASP.NET.

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
 
C

Chris Fulstow

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
 
A

aroraamit81

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???
 
J

jim4u

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
 

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,764
Messages
2,569,567
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top