When the button click event is raised, the value of the selectedindex of
the listbox is stored in the viewstate.
After refreshing the page using response.redirect, I want the listbox
selectedindex to be the value in the viewstate but value is always 0
instead.
Why is that?
Thanks.
JN
Steve C. Orr - 15 Feb 2006 18:57 GMT
ViewState only persists between postbacks to the same page.
Response.Redirect is not a postback.
If you want the value to persists between different pages you'll probably
want to use Session or Application state instead of ViewState.
If you're intending to stay on the same page then why are you using
reponse.redirect?

Signature
I hope this helps,
Steve C. Orr
MCSD, MVP
http://Steve.Orr.net
> When the button click event is raised, the value of the selectedindex of
> the listbox is stored in the viewstate.
[quoted text clipped - 7 lines]
> Thanks.
> JN
JN - 15 Feb 2006 18:58 GMT
Thanks! Session state did the trick.
If I wanted to stay on the same page, how would I refresh it?
> ViewState only persists between postbacks to the same page.
> Response.Redirect is not a postback.
[quoted text clipped - 14 lines]
>> Thanks.
>> JN
Steve C. Orr - 15 Feb 2006 20:31 GMT
I'd probably use a little javascript to submit the form so it posts back.

Signature
I hope this helps,
Steve C. Orr
MCSD, MVP
http://Steve.Orr.net
> Thanks! Session state did the trick.
>
[quoted text clipped - 18 lines]
> >> Thanks.
> >> JN
Teemu Keiski - 15 Feb 2006 18:59 GMT
Hi,
redirect is the same as coming to completely refreshed page (e.g starting
from 0). ViewState is persisted only on postbacks. eg when you make a POST
request to the page with posted data (also having the viewstate hidden
field's data). Redirect does not post, so there's not any viewstate involved
and controls cannot keep their state. If you cannot make it as a postback
instead of redirecting, you could use session variables to store the index
and restore on after redirecting.
See: Understanding ASP.NET ViewState
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnaspp/html/vie
wstate.asp

Signature
Teemu Keiski
ASP.NET MVP, AspInsider
Finland, EU
http://blogs.aspadvice.com/joteke
> When the button click event is raised, the value of the selectedindex of
> the listbox is stored in the viewstate.
[quoted text clipped - 7 lines]
> Thanks.
> JN