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 ();
}