please help me,
how to use session variable ,any body give sample coding in asp.net
Asp.net with c#
4 Answers
Know the answer? Post it. Somebody with the same question will find it here.
Know the answer? Post it. Somebody with the same question will find it here.
Lee27 pointsPosted Jun 19, 2006, 2:20 AM EDT
Hi,
in the "Global.asax.cs"
protected void Session_Start(Object sender, EventArgs e)
{
Session["var"] = "";
}
in your code
writing to a Session variable:
Session["var"] = "string";
reading from a Session variable:
<local variable> = Session["var"].ToString();
I hope this helps!
Lee
hema chandran7 pointsPosted Jun 19, 2006, 2:28 AM EDT
Thanks for ur sample code
Former memberPosted Jun 24, 2006, 6:40 PM EDT
it is correct. But if you get the value from session object before you must validate this. using the property for validation
for example:
if session object contain string value.
public string _username
{
get
{
object o= Session["username"];
if(o!=null)
return (string)o;
else
return null;
}
}
In your method, you call the session like
string login name=_username; //_username is a property value that contain the Session value.
try this.
sreekanth mg33 pointsPosted Jun 28, 2006, 2:29 AM EDT