473,396 Members | 1,895 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,396 software developers and data experts.

Maintaining variable state on web form

Das
Hi all,
I'm using Asp.net. Within a form I have declared declared a public variable. When the form is loaded I set the property for the variable. but it doesn't maintain its state on postback. I there any way to maintain the state for variable?

Thanks,

Das
Nov 16 '05 #1
1 1809
There are a few different ways using "State Bags". Two of them are the
Session collection and the ViewState collection.

The ViewState collection is valid while the current page is up.Meaning, if
the page is refreshed, the ViewState values remain, but as soon as you leave
the page, your ViewState values are gone.

The Session collection exists for the lifetime of the user's session on your
web site, so it's a good way to pass information from one page to another.

The collections are dictionaries that hold objects, so you can do stuff
like:

ViewState["UserName"] = userNameTextBox.Text;

and then elsewhere,

string userName = ViewState["UserName"].ToString()
You can store other data types of course, but you'll need to convert
them from objects to whatever the destination type is.

Session works the same way. Both are members of the Page (well
technically, ViewState is a member of Control, but Page derives, eventually,
from Control).

The primary use of ViewState is to store control state information, but
using it for your own values is perfectly legitimate.

Pete

"Das" <Da*@discussions.microsoft.com> wrote in message
news:91**********************************@microsof t.com...
Hi all,
I'm using Asp.net. Within a form I have declared declared a public variable. When the form is loaded I set the property for the variable. but
it doesn't maintain its state on postback. I there any way to maintain the
state for variable?
Thanks,

Das

Nov 16 '05 #2

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

Similar topics

2
by: Phil Powell | last post by:
print_r("From index.php 20: $prefix: stateXML = $stateXML<P>"); foreach (array('state', 'country') as $prefix) { print_r("From index.php 21: stateXML = $stateXML<P>"); ${$prefix . 'XML'} =...
5
by: leegold2 | last post by:
Probably a newbie question about "state": My problem is I have a search form, so user enters a keyword <enter>, then this form posts to another page were the result are displayed. But this...
0
by: Jesper Lauridsen | last post by:
I am developing an ASP.NET application for a Questionnaire that spans over several pages. The entire Questionnaire code resides in one ASPX page. When a user submits a questionnaire page by...
2
by: Chris | last post by:
Hi, I am building a single webform/webpage asp.net application using VB.NET. I have created lots of classes for this web application. On page load I use a facade controller pattern class to...
1
by: DwC | last post by:
Hey All, I have a web service that maintains it's own state so once the user has successfully called the Login method a logged in flag is set in session. Each method checks that the user is...
7
by: MgGuigg | last post by:
Hello all, This is my first time posting a question to this forum, so here is hoping I am following protocol. I am scraping the rust off my old Basic programming skills, and have just recently...
0
by: mark.norgate | last post by:
Hi I'm having a problem in adding controls to a page programmatically in response to a button click. Composite user controls added programmatically in the CreateChildControls() method work...
4
by: Sam | last post by:
I have an asp.net 2.0 app that uses a sitemap, Master Page, and has several content pages. While this feature has simplified the process of creating a data-driven site menu, it does seem to have...
3
by: Mahathi | last post by:
Hi I have a small problem in maintaining the state of a check box. Please do me a favour by telling me the procedure how to do that. My requirement is that "I have to map some roles with...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.