There are currently 4 types of known:
1 hyperlinks
2, Response.Redirect ("URLString")
3, Server.Transfer ("URLString")
4, PostBackUrl
Hyperlinks:
The first is to add a new Web form and then add a hyperlink to the original default page.
<asp:hyperlink id="HyperLink1" runat="server " Navigateurl="~/default2.aspx"> go to target page </asp:HyperLink>
The value of the NavigateUrl here is a relative path, and the location of the page is also in the same project. Run Web page
Take a look at the source code of this page asp:hyperlink has been compiled into the HTML hyperlink tag.
<div id="div_result"> <a id="HyperLink1" href= " default2.aspx > Go to thetarget page </a> </div>
If the Asp:hyperlink navigateurl= "www.baidu.com", then when clicking on the hyperlink will be an error
You can see that the value of NavigateUrl if you write the URL directly, the system will think this is a relative path, when clicking on the hyperlink will automatically add HTTP before it. So if you want to access a page other than the project, you need to
<asp:hyperlink id="HyperLink1" runat="server " Navigateurl= "http://www.baidu.com"> go to target page </asp:HyperLink>
In addition to Asp:hyperlink, in ASP.
<a href="default2.aspx"> I also go to target page </a>
Both the source code in the browser is the same, and the difference is that the former is a Web control that can take on more actions in the background code, such as having the hyperlink text display different strings as needed, or different pages that can be positioned.
Response.Redirect:
This is a redirect, the server gives the browser a redirect instruction. Add a button to the default page in the background code
protected void Button1_Click (object sender, EventArgs e) { Response.Redirect (" Default2.aspx"); }
The same here, if you want to access a page other than the project, you need to add an HTTP
Response.Redirect execution process is: Browser operation ===> Server compilation ====> send back to page ===> browser makes a request by new URL ===> server responds to new URL request ===> compile new page = = > Send back to the browser.
Note that the redirect request is just a GET request, which means that we cannot submit the data from the source page through the redirect command. But we can use the query string to pass the data in the redirect. As shown in the following code:
protected void Button1_Click (object sender, EventArgs e) {Response.Redirect ("default2.aspx? Username=" + Username.text));}
The above example passes a query string as a parameter to the destination URL of the Response.Redirect method. We can get the source data by the following code.
protected void Page_Load (object sender, EventArgs e) { string userName = request[" UserName " ]; }
Server.Transfer:
This is also a server redirection, but it only happens on the server side without notifying the browser. Execution process:
Browser Operation ===> Server compiles ====>server.transfer redirect ===> server responds to a new URL request ===> compiles a new page ====> sends back to the browser.
Comparison of two redirects:
Server.Transfer can only redirect Web pages within the station, in the background code of the button through the Server.Transfer to access the default2.aspx,
You can see that the URL in the address bar has not changed and is still the address of the default page.
PostBackUrl:
Any control that has a IButtonControl interface has a PostBackUrl property that defines the address of the destination page. (Can be the site, can also be outside the station). This way of jumping, the target page can invoke the value of the control on the original page.
Add a Asp:linkbutton control to the page that has the PostBackUrl property.
<asp:linkbutton id="LinkButton1" runat="server " Postbackurl="~/default2.aspx">LinkButton</asp:LinkButton>
After running the program, view the Web page source code
<a id="LinkButton1" href="javascript:webform_ Dopostbackwithoptions (New Webform_postbackoptions (" Linkbutton1", "", false, "", "default2.aspx", false, true))">LinkButton</a>
Now look at how to implement the PostBackUrl jump target page to invoke the value of the control in the original page:
This is the control code in the original page.
<asp:linkbutton id= "LinkButton1" runat= "Server" postbackurl= "~/default2.aspx" > I am linkbutton</asp: Linkbutton>
In the target page
protected void Page_Load (object sender, EventArgs e) { if( Previouspage.iscrosspagepostback) { = (LinkButton) previouspage.findcontrol (" LinkButton1"); = b.text; } }
<div> <p> I am the target page </p> <asp:label id= "Label1" runat= "Server" text= "Label" ></asp: Label> </div>
The page after the jump
How to jump on an ASP page