1. ASPServer Object Execute method
The Execute method of an ASP server object can insert the contents of another page execution result into the output of the current page during the execution of the current page. The Execute method takes a parameter, which is a string that specifies the location of the ASP file to execute. If an absolute path is provided, the path must be in the same application space. The Execute method provides an alternative to server-side containment and allows the consumer to develop its own collection of reusable modules as a simple script page. The parameters passed to the keynote ASP page can be obtained from the executed page. All output generated by the executed page is added to the output generated by the keynote page.
Tip Server.Execute (path) is suitable for a full page to be transferred to the current page, the page being called into itself can also be a full ASP page. However, its disadvantage is that the current page-defined procedure, function, or variable is not available on the target page. If you are passing parameters, you can save the parameters to the session object. Grammar
Server.Execute (PATH)
Example
WebForm1.aspx:
Response.Write ("Label1.Text");
Server.Execute ("webform2.aspx");
Webform2.aspx:
Response.Write ("Label1.Text");
2 , using 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.
3 , using 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. For example:
1, create a Web Form
2, place a button1 in a new Web form, place two textbox1,textbox2 ,
3, create a Click event for button buttons
The code is as follows:
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 Page_Load of WebForm2:
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");
}
To see the results after delivery.
4 , using 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:
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;
}
. NET several common methods of page jump transfer value