First, the use of QueryString
QueryString is a very simple way of passing values, and the disadvantage is that the value to be transferred is displayed in the address bar of the browser, and the object cannot be passed in this method. This approach is best if you want to pass a security that is not so important or a simple value. Below is a small example to complete the work of the pass, the steps are as follows:
1. Create a Web Form
2. Place a button1 in the new Web form, placing two Textbox1,textbox2
3. Create Click events for button buttons
The code is as follows:
private void button1_click
(object sender, System.EventArgs e)
{
string URL;
Url= "Webform2.aspx?name=" +
TextBox1.Text + "&email=" +
TextBox2.Text;
Response.Redirect (URL);
}
4. Create a new target page named WebForm2
5. Place two Label1,label2 in WebForm2
Add the following code to the WebForm2 Page_Load:
private void Page_Load
(object sender, System.EventArgs e)
{
label1.text=request.querystring["Name"];
label2.text=request.querystring["email"];
}
Run, you can see the results after delivery.
Second, use the session variable
Using session variables to pass values is one of the most common ways to pass values not only to the next page, but also to multiple pages, until the value of the session variable is removed and the variable disappears. Let's take a look at:
1. Create a Web Form
2. Place a button1 in the new Web form, placing two Textbox1,textbox2
3. Create Click events for button buttons
The code is as follows:
Reference content:
private void button1_click
(object sender, System.EventArgs e)
{
session["Name"]=textbox1.text;
session["Email"]=textbox2.text;
Response.Redirect ("webform2.aspx");
}
4. Create a new target page named WebForm2
5. Place two Label1,label2 in WebForm2
Add the following code to the WebForm2 Page_Load:
private void Page_Load
(object sender, System.EventArgs e)
{
label1.text=session["Name"]. ToString ();
label2.text=session["Email"]. ToString ();
Session.remove ("name");
Session.remove ("email");
}
Run, you can see the results after delivery.
Third, the use of Server.Transfer
Although this approach is somewhat complex, it is also a way of passing values on a page.
Let's take a look at:
1. Create a Web Form
2. Place a button1 in the new Web form, placing two Textbox1,textbox2
3. Create Click events for button buttons
The code is as follows:
Reference content:
private void button1_click
(object sender, System.EventArgs e)
{
Server.Transfer ("webform2.aspx");
}
4. Create the procedure to return the value code for the Textbox1,textbox2 control as follows:
public string Name
{
Get
{
return TextBox1.Text;
}
}
public string EMail
{
Get
{
return TextBox2.Text;
}
}
5. Create a new target page named WebForm2
6. Place two Label1,label2 in WebForm2
Add the following code to the WebForm2 Page_Load:
private void Page_Load
(object sender, System.EventArgs e)
{//Create an instance of the original form
WebForm1 WF1;
Get the instantiated handle
wf1= (WebForm1) Context.Handler;
Label1.text=wf1. Name;
Label2.text=wf1. EMail;}
A brief talk on several methods of transmitting value in ASP