Using session objects to pass and share data in ASP [session usage]

Source: Internet
Author: User

The following describes the use of Session objects to pass and share data usage in asp:

1, pass the value:

First, define a text value or a single value to the session, as follows:

session["Name"]=TEXTBOX1.TEXT; assigns the value of text 1 to the session variable name, which can be passed when the other page is investigated, and is still present, and this value is called or judged.

If (session["name"]==null)

{}

Else

{

lable1.text=session["Name"].tostring (); Pass the session variable to Lable1.text

}

2. Delivery Web page:

The following is a button event:

session["Address" = "index.aspx";

Response.Redirect (session["address"). ToString ());

3.session Concrete Method Introduction:

The session object corresponds to the HttpSessionState class in. NET, which means "conversation state", which can hold information related to the current user session.

The session object is used to store the information that is required for a particular user session from the beginning of a user's access to a particular ASPX page, until the user leaves. The variables of the session object are not cleared when the user switches the application's page.

For a Web application, the content of the Application object accessed by all users is exactly the same, while the content of the session object accessed by different user sessions varies. Session can save the variable, which can only be used by one user, that is, each Web browser has its own session object variable, that is, the session object is unique.

(1) Add new item to session state

The syntax format is:

Session ("key name") = value

Or

Session.add ("Key Name", value)

(2) Get the value in session state by name

The syntax format is:

Variable = Session ("Key Name")

Or

Variable = session.item ("Key Name")

(3) Delete an item in the session-state collection

The syntax format is:

Session.remove ("Key Name")

(4) Clear all values in the session state

The syntax format is:

Session.removeall ()

Or

Session.clear ()

(5) Cancel the current session

The syntax format is:

Session.Abandon ()

(6) Sets the time-out period for session state, in minutes.

The syntax format is:

Session.Timeout = value

2 events in the Global.asax file are applied to the session object

Event name Description

Session_Start fires when a session is started

Session_End fires at the end of a session

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.