473,322 Members | 1,259 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,322 software developers and data experts.

ViewState Question

JN
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

Feb 15 '06 #1
4 1901
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?

--
I hope this helps,
Steve C. Orr
MCSD, MVP
http://Steve.Orr.net

"JN" wrote:
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

Feb 15 '06 #2
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/de.../viewstate.asp

--
Teemu Keiski
ASP.NET MVP, AspInsider
Finland, EU
http://blogs.aspadvice.com/joteke

"JN" <jn*****@rogers.com> wrote in message
news:eb**************@TK2MSFTNGP14.phx.gbl...
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

Feb 15 '06 #3
JN
Thanks! Session state did the trick.

If I wanted to stay on the same page, how would I refresh it?

"Steve C. Orr" <St***@Orr.net> wrote in message
news:04**********************************@microsof t.com...
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?

--
I hope this helps,
Steve C. Orr
MCSD, MVP
http://Steve.Orr.net

"JN" wrote:
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

Feb 15 '06 #4
I'd probably use a little javascript to submit the form so it posts back.

--
I hope this helps,
Steve C. Orr
MCSD, MVP
http://Steve.Orr.net

"JN" wrote:
Thanks! Session state did the trick.

If I wanted to stay on the same page, how would I refresh it?

"Steve C. Orr" <St***@Orr.net> wrote in message
news:04**********************************@microsof t.com...
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?

--
I hope this helps,
Steve C. Orr
MCSD, MVP
http://Steve.Orr.net

"JN" wrote:
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


Feb 15 '06 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

10
by: neo | last post by:
hi, I am studying ASP.NET and have few questions - 1) The session ID and values of controls is stored in VIEWSTATE variable. So now when we put EnableViewState="false" in Page directive and...
3
by: Kevin Gorski | last post by:
This question has been asked before, but there have been no definitive answers that I was able to find. Can the viewstate hidden input field be moved to a less prominent page location? On an...
1
by: Simon | last post by:
Hi everyone, I have a quick question that I hope someone can help me with: I've made a user control that contains a text box and some validation functionality. This control has a few extra...
7
by: et | last post by:
I'm not sure I understand the use of the ViewState. Do I understand correctly that values of controls are automatically held in a hidden control called ViewState? If so, then why can't we get...
1
by: olduncleamos | last post by:
Hello all, I am experimenting with the repeater control and ran into something that I wasn't expecting. I would appreciate if the experts can confirm or correct my understanding. Here is a...
6
by: John | last post by:
Hi all, I am using dynamic user controls within my web app and these controls are loaded into placeholders via the LoadControl method. My problem is this: I have usercontrolA loaded into a...
9
by: Mark Broadbent | last post by:
Been a while since I've touched asp.net but one thing that always seems to fustrate me is the loss of state on variable declarations. Is there anyway (i.e. assigning an attribute etc) to instruct...
1
by: Mark Olbert | last post by:
I have a "master" composite control which, in turn, holds an instance of a "detail" composite control (the "master" control will ultimately contain multiple instances of the "detail" control, but...
3
by: Justin | last post by:
I have aspx pages with 10 checkboxlist controls. total individual checkbox (the sum of individual checbox in those 10 checkboxlists) on the page is about 1710. You can imagine how large the...
9
by: =?Utf-8?B?TUNN?= | last post by:
I'm sure the answer to my question varies depending on the situation, but I am looking for a general "best practice". If I have an asp.net application and I load certain data from a database,...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.