Implementation of "back to previous page" and "previous step" in ASP. NET

Source: Internet
Author: User
ArticleDirectory
    • Method 4
    • Summary
Return operations are often used during website construction. Today, we will summarize the common methods used in ASP. NET Website development. In addition to providing high-quality website construction services, hichina Internet also provides a large number of website construction technologies to share more experiences with you. We also hope that everyone can support us and follow us!

Method 1:

<Input type = "button onclick =" javascript: window. History. Go (-1); "value =" back to previous page ">

Method 2

In The onclick Event Response Function of the button, write the following Code :

This. clientscript. registerclientscriptblock (this. getType (), "E", " ", true);

Analysis:

If the current page is a and the previous page is B, when the button in a is pressed, page a is immediately sent back to the server for processing, the server adds the script block we wrote to page.

We felt that after the button was pressed, the page was refreshed. What we saw was not page A, but a new A + page. A + had a script block more than.

When the browser parses a + Page and encounters a script block, it executes the Javascript statement and then two steps are taken back when it runs to history. Go (-2. First, return from page A + to page A and then from page a to page B.

Therefore, the entire rollback process is completed.

 

In method 1, only one step is returned because its button does not have the runat = "server" attribute. Therefore, the button is not sent back to the server after being pressed, so only one step is returned, from A to B.

Method 3

Add in page_load

If (! Ispostback)

Viewstate ["retu"] = request. urlreferrer. tostring ();

 

In the return button event

If (viewstate ["retu"]! = NULL ){

Response. Redirect (viewstate ["retu"]. tostring ());

}

Else

{

Response. Write ("sorry, the current is the front page number");

}

Note:

When request. urlreferrer is used:

1. If the document. location method is used on the previous page to navigate to the current page, request. urlreferrer returns a null value.

2. If there are two pages a and B, directly request page A in the browser and navigate to page B in the page_load event of page A, then request. urlreferrer returns NULL. Because the page has not been initialized in the page_load event, you cannot record the information of the current page. If you navigate to page B, you cannot obtain the information of the previous page.

3. clicking the refresh button will not change request. urlreferrer

Method 4

<A href = <% = request. servervariable. getvalues ("http_referre") %> previous page </a>

Summary

Method 1 and 2 notify the browser to return to the previous page through JavaScript, And the browser will call up the previous page data in the local cache. Therefore, after returning to the previous page, the form data is retained.

Methods 3 and 4 record the URL of the previous page on this page, and then send an HTTP request to the server again when you click the previous page, therefore, the "Previous Page" you get will be a brand new page, and the previously filled form data will not be available.

Therefore, when returning an event, consider that you do not need to refresh the page after returning to the previous page, and then select the corresponding method.

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.