NET (C #) Web page jump Seven methods summary

Source: Internet
Author: User

1.Response.Redirect
This jump page method jumps fast because it wants to go 2 back and forth (2 times postback), but he can jump to any page, no site page limit (ie can be jumped from Yahoo to Sina), and cannot skip login protection. But slow is its biggest flaw!redirect jump mechanism: The first is to send an HTTP request to the client, the notification needs to jump to a new page, and then the client sends a jump request to the server side. It is important to note that all data stored in the internal space after the jump is lost, so the session needs to be used.
Instance:

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 a httpexception to Terminate.response.Redirect ("Http://www.jb51.net", False);}}}

2.Result of the page

http/1.1 302 Found content-type:text/html; Charset=utf-8 location:http://www.jb51.net server:microsoft-iis/7.0 Date:fri, 21:18:34 GMT Content-Length: 144 

3.sever.execute
This method is mainly used on the page design, and he must jump to the same site under the page. This method is used when inserting the output of one page into another ASPX page, most of which is in a table, where a page is similar to a nested way in another 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 The CREATE procedure to return the value code for the Textbox1,textbox2 control is 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 instantiated handle wf1= (WEBFORM1) context.ha Ndler; Label1.text=wf1. Name; Label2.text=wf1. EMail; }

7.server.transfer

Fast, only need one postback, but .... He must be under the same site because it is a method of server. In addition, he can skip login protection. You can write a small program to try: Design a jump from page to page two, but to enter the page two need to login, form authentication, but if the jump statement using transfer, then it will not pop up the login page. The redirect request for this method occurs on the server side, so the URL of the browser is still reserved for the original page's address!

<%@ 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 "> Summarize:

If you want to capture the output of an ASPX page and then insert the result into a specific location on another ASPX page, use Server.Execute.
• If you want to ensure that the Html output is legitimate, use Response.Redirect because the page that Server.Execute or Server.Transfer method returns to the client contains multiple <Html><body> tags , not a legitimate HTML page, and errors may occur in non-IE browsers.

1.response.redirect ("Http://www.jb51.net", false);
The target page and the original page can be on 2 servers, and you can enter a URL or relative path. The bool value that follows is whether to stop executing the current page.
Jump to a new page, the original window is replaced. "
The URL in the browser is the new path.
: The Response.Redirect method causes the browser to link to a specified URL. When the Response.Redirect () method is called, it creates an answer that is indicated in the answer header
Status Code 302 (indicates that the target has changed) and the new destination URL. The browser receives the reply from the server and uses the information in the reply header to make a request to the new URL. Say
When using the Response.Redirect method, the redirect operation occurs on the client, involving a total of two communications with the server (two back and forth): the first is a request to the original page,
Get a 302 answer, and the second is a new page declared in the Request 302 reply, to get the page after the redirect.
2.server.transfer ("Default2.aspx?name=zhangsan", true);
The target page and the original page can be on the same server.
Jump to a new page, the original window is replaced.
Wave Ball Forum The URL in the browser is the same as the original path.
By default, the Server.Transfer method does not pass the form data or query string from one page to another, but only if the second parameter of the method is set to
Tb310true, you can keep the form data and query strings for the first page.
At the same time, it should be noted when using Server.Transfer: The target page will use the original page to create an answer stream (machine authentication Check,mac) that the viewstate of the new page has been tampered with. Therefore, if you want to preserve the form data and query string collections of the original page,
You must set the enableViewStateMac property of the page directive of the target pages to false.
3.server.execute ("default5.aspx?address=beijing");
The target page and the original page can be on the same server.
Jump to a new page, then jump to the original page.
The URL in the browser is the same as the original path.
When the specified ASPX page finishes executing, the control flow returns to the original page where the Server.Execute call was made.
This kind of page navigation is similar to a function call on an ASPX page, where the called page has access to the form data and query string collection that made the calling page, so
The enableViewStateMac property of the paged page directive is set to false.
4.response.write ("<script language= ' JavaScript ' >window.open (' aaa.aspx ');</script>"); _
The target page and the original page can be on 2 servers, and you can enter a URL or relative path.
The original window is reserved and another new page is added.
5.response.write ("<script language= ' javascript ' >window.location= ' default2.aspx ' </script>");
Open a new page, the original window is replaced.
6.response.write ("<script>window.showmodaldialog (' default2.aspx ') </script>");
7.response.write ("<script>window.showmodelessdialog (' default2.aspx ') </script>");

For more information, refer to: http://www.jb51.net/article/21046.htm

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.