Asp. NET cross-page pass value--application

Source: Internet
Author: User

Asp. NET cross-page pass-through values

The Application object is scoped to the whole global, which means it is valid for all users. It is valid throughout the application life cycle, similar to using global variables, so it can be accessed from different pages. It differs from the session variable in that the former is a global variable shared by all users, and the latter is a unique global variable for each user.

One might ask, since all users can use the application variable, where can he use it? Here's an example: the number of site visits. It can be manipulated when multiple requests are accessed.

Advantages:

1. Easy to use, consumes less server resources.

2. Not only can pass the simple data, but also can pass the object.

3. The size of the data volume is unlimited.

Disadvantages:

1. It is easy to operate as a global variable. Therefore, the variables used by individual users are generally not application.

How to use:

1. Create the name and value you need to pass in the source page code to construct the application variable: application["Nmae"]= "Value (Or Object)";

2. The code on the destination page uses the application variable to remove the passed value. Result = application["Nmae"]

Note:  

common Lock and Unlock methods are used to lock and unlock, in order to prevent concurrent modifications.

Example:

(1) a.aspx

private void Button1_Click (object sender, System.EventArgs e) {application["name"] = Label1.Text;}

(2) b.aspx

private void Page_Load (object sender, EventArgs e) {string name;   Application.Lock (); Name = application["Name"].   ToString (); Application.UnLock (); }

Asp. NET cross-page pass value--application

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.