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();
}
3. Use Session Variables
Presumably this is the most common use of everyone, its operation is similar to application, the role of users, so, excessive storage will lead to the depletion of server memory resources.
A.aspx's C # code
private void Button1_Click(object sender, System.EventArgs e)
{
Session["name"] = Label.Text;
}
C # code in b.aspx
private void Page_Load(object sender, EventArgs e)
{
string name;
name = Session["name"].ToString();
}