Home All Groups Group Topic Archive Search About
Author
7 May 2005 10:08 AM
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.

Author
8 May 2005 8:24 PM
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


Jasmine wrote:
Show quoteHide quote
> 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.
>
>
>
>
>
>