asp.net tutorial: Five Ways to page-pass values

Source: Internet
Author: User

Asp. NET Cross page transfer value Skill summary

A lot of discussion has been raised about the way pages are passed. It seems that there are a lot of people concerned about this, I made a summary of my personal point of view, I hope to help.

1. Using QueryString variables

QueryString is a very simple way of passing values, and he can display the value of the transfer in the browser's address bar. You can use this method if you pass one or more values that are not of high security requirements or are simple in structure. However, this method is not available for passing arrays or objects. Here is an example:

A.aspx's C # code

private void Button1_Click (object sender, System.EventArgs e)
{
String S_url;
S_url = "B.aspx?name=" + Label1.Text;
Response.Redirect (S_url);
}

C # code in b.aspx

private void Page_Load (object sender, EventArgs e)
{
Label2.Text = request.querystring["name"];
}

2. Using Application Object variables

The scope of the Application object is the entire global, which means it works for all users. Its commonly used methods are lock and unlock.

A.aspx's C # code

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

C # code in b.aspx

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



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.