Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Textbox GET & SET
Message
 
To
17/12/2002 15:26:47
Larry Long
ProgRes (Programming Resources)
Georgia, United States
General information
Forum:
ASP.NET
Category:
Web forms
Miscellaneous
Thread ID:
00733837
Message ID:
00733849
Views:
25
>Can someone show me an example of how to do a GET & SET for a web form textbox control? I want to initialize the textbox value with a Session variable that needs to persist. I've added a Session variable to the web.config file but cannot get it to work.
>
>Thanks,
>Larry Long

It's not really necessary to add that to the web.config. Code like this should work (from within your Page_Init() of your .aspx.cs file), assuming you have a lable control named "lblTest" on the form.
if (Session["Variable"] == null)
{
   Session.Add("Variable", "Hello");
}		   	
else
{
   this.lblTest.Text = Session["Variable"].ToString();
}
(although I'm showing a label, a textbox works exactly the same way).

This is the "Set" portion of it. To "Get", depending on how you are posting variables to/from the pages (through querystring values or via POST), you retrieve the variables using the Request object:
// Querystring
if (Request.QueryString["SomeVariable"] != null)
{
   // Save the querystring variable into the session
   Session["SomeVariable"] = Request.QueryString["SomeVariable"];
}

// Post
if (Request.Form["SomeVariable"] != null)
{
   // Save the posted variable into the session
   Session["SomeVariable"] = Request.Form["SomeVariable"];
}
-Paul

RCS Solutions, Inc.
Blog
Twitter
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform