473,386 Members | 1,766 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,386 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 1907
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: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...

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.