Home All Groups Group Topic Archive Search About

ListBox not firing SelectedIndexChanged (AutoPostBack=True)

Author
14 Jun 2005 4:22 AM
danob7
To all .Net gurus out there;

I have a simple ASP.Net Form, in which I added a ListBox control.  I
populate the content of that ListBox at run time.  To save on footprint size,
I set EnableViewState=False.

But by doing that, the SelectedIndexChanged stops working (AutoPostBack is
still = True).  Any know of this odd behavior?

I have a Response.Redirect in my SelectedIndexChanged function, so I have no
need to keep EnableViewState=True.  And since any click would result in a
redirect, I have no need to "re"load the ListBox on page_load if IsPostBack.

I know this can be solved by turning EnableViewState = True, but that would
also make the rendered HTML & view state blob grow at an exponential rate
when listbox contains hundreds of items...

Can anyone help?

Author
14 Jun 2005 1:00 PM
Brock Allen
If you rely upon the SelectedIndex change behavior from the DDL, you must
enable viewstate. You can get away with repopulating the items in Page_Init,
but the way the DDL knows if it was changed is it stores the last selected
index in ViewState. So if you disable it, then it won't work correctly.

-Brock
DevelopMentor
http://staff.develop.com/ballen



Show quoteHide quote
> To all .Net gurus out there;
>
> I have a simple ASP.Net Form, in which I added a ListBox control.  I
> populate the content of that ListBox at run time.  To save on
> footprint size, I set EnableViewState=False.
>
> But by doing that, the SelectedIndexChanged stops working
> (AutoPostBack is still = True).  Any know of this odd behavior?
>
> I have a Response.Redirect in my SelectedIndexChanged function, so I
> have no need to keep EnableViewState=True.  And since any click would
> result in a redirect, I have no need to "re"load the ListBox on
> page_load if IsPostBack.
>
> I know this can be solved by turning EnableViewState = True, but that
> would also make the rendered HTML & view state blob grow at an
> exponential rate when listbox contains hundreds of items...
>
> Can anyone help?
>