Web page value passing method, web page value passing Method

Source: Internet
Author: User

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

Related Article

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.