1. Use querystring variable
Querystring is a simple method for transferring values. It can display the transmitted values in the address bar of a browser.
This method can be used to transmit one or more numeric values with low security requirements or simple structure. However, this method cannot be used to pass arrays or objects. The following is an example:
A. aspx C #Code
Private Void Button#click ( Object Sender, system. eventargs E)
{
String S_url;
S_url =" B. aspx? Name = "+ Label1.text;
Response. Redirect (s_url );
}
B. C # code in aspx
Private VoidPage_load (ObjectSender, eventargs E)
{
Label2.text = request. querystring ["Name"];
}
2. Use the application object variable
The scope of the Application object is global, that is, it is valid for all users. The common methods are lock and unlock.
A. aspx C # code
Private VoidButton#click (ObjectSender, system. eventargs E)
{
Application ["Name"] = Label1.text;
Server. Transfer ("B. aspx");
}
B. C # code in aspx
Private VoidPage_load (ObjectSender, eventargs E)
{
StringName;
Application. Lock ();
Name = application ["Name"]. Tostring ();
Application. Unlock ();
}
3. Use session Variables
Presumably, this is definitely the most common usage. Its operations are similar to those of the application, which act on individual users. Therefore, excessive storage will result in the depletion of server memory resources.
A. aspx C # code
Private VoidButton#click (ObjectSender, system. eventargs E)
{
Session ["Name"] = Label. text;
}
B. C # code in aspx
Private VoidPage_load (ObjectSender, eventargs E)
{
StringName;
Name = session ["Name"]. Tostring ();
}
4. Use cookie object variables
This is also a common method. Like session, it is for every user, but there is a fundamental difference, that is, cookies are stored on the client, session is stored on the server.
In addition, the use of cookies should be used in combination with the ASP. NET built-in Object Request.
A. aspx C # code
Private VoidButton#click (ObjectSender, system. eventargs E)
{
Httpcookie cookie_name =NewHttpcookie ("Name");
Cookie_name.value = label1.text;
Reponse. appendcookie (cookie_name );
Server. Transfer ("B. aspx");
}
B. C # code in aspx
Private VoidPage_load (ObjectSender, eventargs E)
{
StringName;
Name = request. Cookie ["Name"]. Value. tostring ();
}
5. Use the server. Transfer Method
This can be said to be the method used by face object development. It uses the server. Transfer Method to direct the process from the current page to another page,
The new page uses the response stream of the previous page, so this method is completely object-like, concise and effective.
A. aspx C # code
PublicStringName
{
Get{ReturnLabel1.text ;}
}
Private VoidButton#click (ObjectSender, system. eventargs E)
{
Server. Transfer ("B. aspx");
}
B. C # code in aspx
private void page_load ( Object sender, eventargs E)
{< br> A newweb; // instance a form
newweb = (source) context. handler;
string name;
name = newweb. name;
}< br>