Skip to content

Asp.net with c#

hema chandran

Asked Jun 19, 2006, 1:39 AM EDT4 answers
Share
LinkedInX
please help me,
how to use session variable ,any body give sample coding in asp.net

4 Answers

Know the answer? Post it. Somebody with the same question will find it here.

  • 0

    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

    0
  • 0
    Hai Lee,
    Thanks for ur sample code
    0
  • 0
    I gone through the Lee code for retrive the value from session.
    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.
    0
  • 0
    hhgfhvjhkjhjkgjkkhhgfhvjhkjhjkgjkkhhgfhvjhkjhjkgjkkhhgfhvjhkjhjkgjkkhhgfhvjhkjhjkgjkkhhgfhvjhkjhjkgjkkhhgfhvjhkjhjkgjkkhhgfhvjhkjhjkgjkkhhgfhvjhkjhjkgjkkhhgfhvjhkjhjkgjkkhhgfhvjhkjhjkgjkkhhgfhvjhkjhjkgjkkhhgfhvjhkjhjkgjkkhhgfhvjhkjhjkgjkkhhgfhvjhkjhjkgjkkhhgfhvjhkjhjkgjkkhhgfhvjhkjhjkgjkkhhgfhvjhkjhjkgjkkhhgfhvjhkjhjkgjkkhhgfhvjhkjhjkgjkkhhgfhvjhkjhjkgjkkhhgfhvjhkjhjkgjkkhhgfhvjhkjhjkgjkkhhgfhvjhkjhjkgjkkhhgfhvjhkjhjkgjkkhhgfhvjhkjhjkgjkk
    0