Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / ASP.NET / General / February 2006

Tip: Looking for answers? Try searching our database.

ViewState Question

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
JN - 15 Feb 2006 17:34 GMT
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

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.