Introduction

In the technology of Web development, we have many different methods for page jump. We can use methods provided by ASP.NET built-in objects achieve page jump. We can according to ASP.NET provided server control and HTML control achieve page jump. And we can also use javascript to program formula achieve page jump. Here we will discuss 7 methods for page jump in ASP.NET.

Page Jump Methods

1、 Make use of HTML tags

<a href=”test.aspx”>test page

This example is very simple. Just use href property of tag to formulate the url of jump page to achieve jump.

2、 HyperLink Control

This the most normal method:

  • ASP.NET server control NavigateUrl property specify the destination of Url address.
  • NavigateUrl can be modified by code in server. This is different with
  • Because of HyperLink has no event, we need set NavigateUrl in server.
  • Example code:

<asp:hyperlink id="”hyperlink”" runat="”server”" navigateurl="”test.aspx”">ok</asp:hyperlink>

3、Response.Redirect()

  • Process: Send an Http response to client and inform client jump to a new page. Then, send jump request to server from client.
  • After page jump, all information stored in inside control lost. When A jumped to B, page B can’t visit information submitted by page A.
  • Use this method to jump page the Url information in browser address will be changed.
  • Use Session Cookies Application object to deliver data between pages.
  • Redirect happens at client and will involve twice contact with Web server: request for original page, request for redirect new page
  • This method is not fast because it has 2 postback. But it can jump to any page, no limitation from pages. And at the same time, it can’t pass the login protect.

  • example code:
  • <asp:button id="Button1" runat="server" text="jump" onclick="Button1_Click1" /> 

    Now we add a Button control and program code in relevant cs file.

    protected void Button1_Click1(object sender, EventArgs e)
    {
    Response.Redirect("http://www.e-iceblue.com");
    }
    

4、Server.Transfer()

  • Achieve page jump and at the same time exchange control
  • During page jump process, information stored by Request Session will not change. And it’s available to use the information in the page before jump.
  • After page jump. Url in browser address will not change
  • The redirect request of this method is processed in server. Browser doesn’t know happened a jump.
  • Fast speed! Only need 1 postback but have t under the same site because it’s a method from server. In addition, it can pass login protection.

  • example code:
  • protected void Button1_Click(object sender, EventArgs e)
    {
    Server.Transfer("Server2.aspx");
    }
    

    Note: the path is virtual path which means it can formulate in page from the same category but can’t formulate unconditional address.

5、 Server.Execute()

  • This method allows the present page execute another page in server.
  • After execute page, back to original page and send Server.Execute() position.
  • This is similar with a function cite against page. The requested page can use original page information and consult string assemble.
  • Set EnableViewStateMac property as False
  • example code
  • protected void Button1_Click(object sender, EventArgs e)
    {
    Server.Execute("Server2.aspx");
    }
    

    Note: only virtual path here

6、Javascript achieve page jump

We can make use of javascript in page program formula to achieve page jump

<script type="text/javascript" language="javascript">
// directly jump page 
window.location.href = 'hello.html';
// definite time to jump page
setTimeout("javascript:location.href='hello.html'", 5000);

7、Respone.Write()

In the Write method incoming javascript to achieve page jump. 

Respose.Write( " <script language= "'javascript" '> window.open( ' "+ url + " ');
 ");

Again, introduce you 2 more articles:

推荐.NET配套的通用数据层ORM框架:CYQ.Data 通用数据层框架
新浪微博粉丝精灵,刷粉丝、刷评论、刷转发、企业商家微博营销必备工具"