Asp. Comparison and selection of net four kinds of page navigation methods

Source: Internet
Author: User
Asp. NET application, there are many ways to navigate between Web Forms: with hyperlinks, with Response.Redirect, with Server.Transfer, or with Server.Execute. This article will analyze the similarities and differences of these four kinds of navigation methods and their advantages and disadvantages, and help you choose the best navigation method.
One, Super link
The easiest way to get to another form from one form is to use the HTML Hyperlink control. In Web Forms, HTML code classes that use hyperlinks are as follows:
<a Href= "webform2.aspx" into Form 2 </a>
When the user clicks on the hyperlink, Webform2.aspx executes and sends the results to the browser. Hyperlink navigation can be used almost anywhere, including HTML pages and ordinary ASP pages. Asp. NET also provides another alternative use, the Hyperlink server control:
<form id= "Form1" method= "POST" runat= "Server"
<asp:hyperlink id= "HyperLink1" runat= "Server"
Navigateurl= "webform2.aspx" into form 2 </asp:HyperLink>
</form>
The results of the above HTML code are the same as the first example, because ASP.net treats the Hyperlink Web server control as an HTML hyperlink control. But there is a significant difference between the two, HyperLink Web server controls can be programmed on the server side. Specifically, you can change its NavigateUrl properties in your program code, allowing you to construct hyperlinks that can dynamically change depending on the current state of the application, such as:
Private Sub Button1_Click (_
ByVal sender as System.Object, _
ByVal e As System.EventArgs) _
Handles Button1.Click
Hyperlink1.navigateurl = "Webform3.aspx"
End Sub
After this code executes, if the user clicks on the link, he sees the webform3.aspx, not the webform2.aspx.
Second, using program control redirect
Although hyperlinks can be navigated from one page to another, this navigation is entirely user-controlled. Sometimes, we might want to use code to control the entire navigation process, including when to go to another page. On these occasions, ASP. NET has three different ways to achieve similar goals: Call the redirect method of the Response object, and invoke the transfer or Execute method of the server object. The behavior of these three types of navigation is basically similar, but there are also differences.

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.