Value Transfer Mode between ASP. NET pages-zt

Source: Internet
Author: User
Add a line in the html code of the receiving Page: <% @ Reference Page = "WebForm1.aspx" %>

WebForm1 fp = (WebForm1) Context. Handler;
This. TextBox1.Text = fp. name; // name is the public variable on the first page.
 
 
Context provides access to the entire current Context (including the request object. You can use the information between such shared pages.
 
Method 2: GET
On the send page
Public int sum = 0;
 
Int I = int. Parse (this. TextBox1.Text) * 2;
 
Server. Transfer ("WebForm2.aspx? Sum = "+ I );
 
Receiving page
This. TextBox1.Text = Request ["sum"]. ToString ();
Or this. TextBox1.Text = Request. Params ["sum"]. ToString ();
This. TextBox1.Text = Request. QueryString ["sum"];
 
 
Method 3: global variables
 
Send page:
Application ["sum"] = this. TextBox1.Text;
Server. Transfer ("WebForm2.aspx ");
 
Receiving page:
This. TextBox1.Text = (string) Application ["sum"];
 
Application is essentially a collection of all files in the virtual directory. If you want to use a variable value throughout the Application, the Application object will be the best choice.
 
 
 
Method 4:
 
Send page:
1. Define static variables: public static string str = "";
2. str = this. TextBox1.Text;
Server. Transfer ("webform2.aspx ");
Receiving page:
1. Introduce the namespace on the first page: using WebApplication1;
2 this. TextBox1.Text = WebForm1.str;

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.