Web page value passing method, web page value passing Method
I. Use QueryString variable
QueryString is a simple and widely used method for transferring values, but it displays the passed values in the address bar of the browser, this method can be used to transmit one or more numeric values with low security requirements or simple structure.
Response. Redirect ("target. aspx? Param1 = hellom2 ")
Receiving page: string str = Request. QueryString ["param1"];
2. Use the Cookie object variable (the Cookie is stored on the client)
Set Cookie: HttpCookie cookie_name = new HttpCookie ("name ");
Cookie_name.Value = Label1.Text;
Reponse. AppendCookie (cookie_name );
Get Cookie:
String name = Request. Cookie ["name"]. Value. ToString ();
3. Use Session variables (sessions are stored on the server)
Set Session: Session ["name"] = "hello ";
Get Session: string name = Session ["name"]. ToString ();
4. Use the Application object variable
The scope of the Application object is global, that is, it is valid for all users. This method is not often used. Because the Application is shared within an Application domain, all users can change and set its value. Therefore, only the counters and other places that require global variables are used.
Set Application: Application ["name"] = "hello ";
Obtain Application: string name = Application ["name"]. ToString ();
5. PostBackUrl () method
Default. aspx page:
Code
1 <asp: Button ID = "Button1" Runat = "server" Text = "PostToAnotherPage" PostBackUrl = "~ /Default2.aspx "/>
2
Default2.aspx page:
Code
1 if (PreviousPage! = Null)
2 {
3 TextBox textBox1 = (TextBox) PreviousPage. FindControl ("TextBox1 ");
4 Response. write (textBox1.Text );
5}
6. Use the Server. Transfer Method