checkboxlist help

J

Jasmine

hi all,

In my code I dynamically create web controls. My problem is
newCheckBoxList = new CheckBoxList();

newCheckBoxList.EnableViewState = true;

newCheckBoxList.AutoPostBack = true;

newCheckBoxList.SelectedIndexChanged += new
System.EventHandler(Checked_Changed);

When I create a dynamic checkboxlist like that, I handle the selected index
changed event but my page refreshes and all controls I have drawn
disappears. Instead of that when I only create the checkboxlist and dont
use the last 3 commands, I have selected index -1 when I control the
checkbox list.

Is there any way to store selected indexes without enabling autopostback?

Thanks.
 
S

Scott Mitchell [MVP]

Jasmine, when working with dynamically-created controls it is essential
that you add these controls and their event handlers ON EACH AND EVERY
POSTBACK. Check out these articles for more on working with dynamic
controls in ASP.NET:

http://aspnet.4guysfromrolla.com/articles/081402-1.aspx
http://aspnet.4guysfromrolla.com/articles/082102-1.aspx
http://aspnet.4guysfromrolla.com/articles/092904-1.aspx
http://msdn.microsoft.com/asp.net/default.aspx?pull=/library/en-us/dnaspp/html/DynamicUI.asp

hth
 

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,581
Members
45,056
Latest member
GlycogenSupporthealth

Latest Threads

Top