How to redirect between pages in asp..net

Source: Internet
Author: User

Response. Redirect () method

Use the response. Redirect () method in the following cases:

1. the user connects to resources on another server;

2. connect users to non-aspx resources, such as HTML pages;

3. Use the query string as part of the URL (because the other two methods cannot be PostBack twice );

If you want to use Chinese characters for query, convert string message first.
= Server. urlencode ("Chinese character ");

4. Make sure that the HTML output is valid;

5. Use session cookies
Applications and other objects for data transmission between pages.

Disadvantage: the response is slow (two requests), the control information is lost, and the data submitted on the previous page cannot be accessed.

 

Server. Transfer () method

The response. Transfer () method is used in the following cases:

1. ASPX page conversion (logon not involved );

2. When the page jumps, the control of the page is handed over;

3. the URL in the browser address bar remains unchanged after the jump.

Advantage: request during page Jump
Session and other stored information remain unchanged. After the jump, you can use the data submitted on the previous page. The redirection request of this method is performed on the server side, and the browser does not know that the page has already been redirected once.

Tip: If you want to transfer the execution process to another ASPX page of the same web server, you should use server. transfer instead of response. redirect, because server. transfer can avoid unnecessary network communication to achieve better performance and browsing performance.

 

Server. Execute () method

Use the response. Execute () method in the following cases:

1. execute another page on the same web server;

2. After the page is executed, the location is not changed;

3. Use the form data of the original page and query the string set;

4. Capture the output result of An ASPX page and insert the result to a specific location on the other ASPX page.

Note: This page navigation method is similar to calling the callback function for the ASPX page. The called page can access the form data and query string set of the calling page, therefore, set the enableviewstatemac attribute of the called page command to false. By default, the output of the called page is appended to the current response stream. However, server. the execute method has an overloaded method that allows a textwriter object (or its sub-object, such as the stringwriter object) to obtain the output of the called page, rather than directly appending it to the output stream, on the original page, you can easily adjust the location of the output result of the called page.



<A> tag

This is the most common method of steering;

<A href = "test. aspx"> </a>

 

Hyperlink Control

Hyperlink is an Asp.net server-side control.
The navigateurl attribute specifies the URL address to jump to. navigateurl can be modified on the server side using code.

<Asp: hyperlink id = "HYPERLINK" runat = "server" navigatoeurl = "test. aspx"> OK </ASP: hyperlink>

Summary:

1 response. Redirect
The method used to jump to the page is not fast, because it requires two rounds (two PostBack), but he can jump to any page, there is no website page restriction (that is, you can jump from Yahoo to Sina), and you cannot skip logon protection. However, slow speed is the biggest defect! Redirect jump mechanism: First, send
When an HTTP request arrives at the client, the notification needs to jump to a new page, and then the client sends a jump request to the server. It should be noted that after the jump, all data information stored in the internal space will be lost, so session is required.

2 server. fast transfer, only one PostBack
, .... It must be on the same site because it is a server method. In addition, he can skip logon protection. You can try to write a small program: design a jump from page 1 to page 2, but to enter page 2, You need to log on and perform form authentication. However, if the jump statement uses transfer, the logon page will not pop up. The redirection request of this method occurs on the server, so the URL address of the browser still retains the address of the original page!

3 sever.exe cute
This method is mainly used in the page design, and it must jump to the page under the same site. This method needs to be used to insert the output results of a page to another ASPX page. Most of them are in the table, where a page is nested to another page.

Collect and organize data from networks

Related Article

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.