Click here to Skip to main content
Licence CPOL
First Posted 6 Sep 2011
Views 8,176
Bookmarked 29 times

7 Page Jump Methods in ASP.NET

By | 6 Sep 2011 | Article
Here we will discuss 7 methods for page jump in ASP.NET

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 to 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 is the most normal method:

  • ASP.NET server control NavigateUrl property specifies the destination of URL address.
  • NavigateUrl can be modified by code in server. This is different because HyperLink has no event, we need to 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 is stored 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 postbacks. But it can jump to any page, no limitations 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 the 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 that a jump happened.

    Fast speed! You only need 1 postback but have it 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 a 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 to 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 Achieves 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. Response.Write()

In the Write method incoming JavaScript to achieve page jump.

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

Again, I introduce you to two more articles:

History

  • 7th September, 2011: Initial post

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

About the Author

loveyou999


e-iceblue
United States United States

Member

Follow on Twitter Follow on Twitter


Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board. (secure sign-in)
 
Search this forum  
 FAQ
    Noise  Layout  Per page   
  Refresh
GeneralMy vote of 4 PinmemberPandvi22:47 7 May '12  
GeneralMy vote of 4 PinmemberJenny Quinn2:29 19 Sep '11  
Suggestionanother missing... Pinmemberluizfredericojr6:13 14 Sep '11  
Suggestion[My vote of 1] My vote of 1 PinmemberEngleA4:25 14 Sep '11  
Questionyou are missing one Pinmembertutor4:18 14 Sep '11  
QuestionI meant to vote 5! PinmemberRiverama18:04 13 Sep '11  
GeneralMy vote of 4 PinmemberDilip Baboo13:02 13 Sep '11  
Question[My vote of 1] Just basic ASP.Net 101. PinmemberMr President6:32 13 Sep '11  
GeneralMy vote of 4 PinmemberManuel_Perez_II5:05 13 Sep '11  
GeneralMy vote of 4 Pinmembersupriya chaladi20:07 7 Sep '11  
GeneralMy vote of 4 PinmemberArmando de la Torre7:34 7 Sep '11  
QuestionWhat about location.reload? PinmemberBill SerGio, The Infomercial King6:51 7 Sep '11  
AnswerRe: What about location.reload? PinmemberHaBiX23:44 8 Sep '11  
GeneralRe: What about location.reload? PinmemberBill SerGio, The Infomercial King1:58 9 Sep '11  
QuestionGood one but... PinmemberVani Kulkarni0:51 7 Sep '11  

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Mobile
Web01 | 2.5.120517.1 | Last Updated 7 Sep 2011
Article Copyright 2011 by loveyou999
Everything else Copyright © CodeProject, 1999-2012
Terms of Use
Layout: fixed | fluid