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">
window.location.href = 'hello.html';
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