473,698 Members | 2,888 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 1830
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*@discussion s.microsoft.com > wrote in message
news:91******** *************** ***********@mic rosoft.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
1885
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'} = $this->getXML($prefix . '.xml'); } I have never seen anything like this in my 3+ years of PHP coding! When I ran this code, I get the following output:
5
2259
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 display page uses pagination to break the results up into several subsequent pages. The 1st page is OK, but 2nd...last display pages loose the key word variable I initially posted. Seems I could keep passing the keyword with GET, I already use GET...
0
1257
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 clicking a "Next page" button, I want to 1) validate the answers and 2) render the next page (but still the same ASPX page) if the questionnaire page validates (wizard style). One design solution is to have a session variable hold the current page...
2
1995
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 perform all my initial class object instaniations using sub new() procedures I'm using this project to learn the ins and outs of OOA and OOD, so instead of doing everything in code behind pages I have lots of objects now created
1
1262
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 a valid user and has logged in before returning anything.
7
2575
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 upgraded to VB.NET, and I have a lot of catching up to do. That being said, I have come a long way in a short while, however, I am stumped at the moment. I have read through days of posts, but have not been able to address my specific question, so...
0
1316
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 fine; they maintain their state as expected. Cool and groovy. However, since CreateChildControls() is called before the method that responds to the button click, say AddControl_Click(), for some reason, this control does not maintain its
4
4334
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 some big restrictions. Namely, maintaining state on the Master Page across all content pages. I simply want to keep track of a key value across all content pages. The only solution I can come up with is using a session variable, which I hate.
3
2909
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 that of the users of the project. I have used checkboxes for selecting the roles that a particular user has. For example, an adminstrator has all roles in an organisation. Similarly an Employee has limited roles. Here let us take administrator...
0
8611
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9170
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9031
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8904
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8876
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7741
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6531
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5867
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4372
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...

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.