The first method: Response.Redirect
This jump page method jump speed is not fast, because it will take 2 back (2 times postback), but it can jump to any page, no Site page restrictions (that is, can be jumped from Yahoo to Sina), while not skip login protection. But slow speed is its biggest flaw!redirect jump mechanism: First is sends an HTTP request to the client, the notification needs to jump to the new page, then the client sends the jump request to the server side. Note that all the data information stored in the internal space after the jump is lost, so you need to use the session.
The code is as follows
Using System;
Using System.Web.UI;
Namespace WebApplication1
{public
partial class List:page
{
protected void Page_Load (object sender , EventArgs e)
{
//get response.
var response = base. Response;
Redirect temporarily.
// ... Don ' t throw an httpexception to terminate.
Response. Redirect ("Http://www.jb51.net", False);}}
The code is as follows
http/1.1 302 Found
content-type:text/html charset=utf-8
location:http://www.jb51.net
Server: microsoft-iis/7.0
Date:fri Aug 21:18:34 GMT
content-length:144
The second method of Sever.execute
This method is mainly used on the page design, and he must be to jump the same site under the page. This method is needed to insert the output of one page into another ASPX page, mostly in a table where one page is similar to nesting in another.
For example, 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, the creation process to return the value of the Textbox1,textbox2 control code is as follows:
The code is as follows
public string Name
{
get
{
TextBox1.Text
}
}
public string EMail
{
textbox2.text
}
}
5, a new target page named WebForm2
6. Place two Label1,label2 in WebForm2
Add the following code to the Page_Load of WebForm2:
The code is as follows
private void Page_Load
(object sender, System.EventArgs e)
{
//Create an instance of the original form
WebForm1 wf1;
Gets the instantiated handle
wf1= (WebForm1) Context.Handler;
Label1.text=wf1. Name;
Label2.text=wf1. EMail;
}
The third method: Server.Transfer
fast and requires only one postback, but it must be under the same site because it is a method of the server. In addition, he can skip login protection. You can write a small program to try: Design a page to page two of the jump, but to enter the page two need to login, form certification, but if the jump statement using transfer words, it will not pop-up login page. The redirection request of this method occurs on the server side, so the URL address of the browser still retains the address of the original page!
The code is as follows
<%@ Page language= "C #" autoeventwireup= "true" codefile= "WebForm1.aspx.cs" inherits= "WebForm1"%> <! DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 transitional//en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd ">
Use Server.Execute if you want to capture the output of an ASPX page and then insert the result into a specific location in another ASPX page.
• If you want to make sure that the Html output is legitimate, use Response.Redirect because the Server.Execute or Server.Transfer method returned to the client page contains multiple <Html><body> tags , it is not a legitimate HTML page, and errors may occur in non-IE browsers.
The above three kinds of asp.net page jump method, I hope to help you learn.