Asp.net returns the previous page, and asp.net returns the previous page.

Source: Internet
Author: User

Asp.net returns the previous page, and asp.net returns the previous page.

In fact, JavaScript is mainly used to return to the previous page.

I:

In the source code of aspx in ASP.net

<Input type = "button onclick =" Javascript: window. history. go (-1); "value =" back to previous page ">

Analysis: This is an HTML control. Through an onclick event, you can call a method in javascript. This is the simplest and also applies to static pages and ASP pages.

II:

Use Reponse. write

If you have a certain understanding of ASP, then the Response. write is no stranger to this stuff. The first method is to implement it directly on an HTML page, then it is implemented in the background environment (this statement does not seem very standard, huh, huh)

Response. write ("<script language = javascript> history. go (-2); </script>)

<A href = "#" onclick = "javascript: history. back ();"> return to the previous page </a>

Here we will use the-2 value. I personally think it is like this: Because in asp.net, when you press a button, the page will be implemented. because of postback, the page is actually refreshed twice, and we want it for the first time, so it is ......

III:

Use Response. Redirect () or server. transfer ()

Add in page_load

If (! IsPostBack)

ViewState ["retu"] = Request. UrlReferrer. ToString ();

In the return button event

Response. Redirect (ViewState ["retu"]. ToString ());

Or Server. Transfer (ViewState ["retu"]. ToString ());

 

IV:

Very few people use this method, but I tried it and it was quite good.

In The onClick event of the button, enter

This. RegisterClientScriptBlock ("e", "<script language = javascript> history. go (-2); </script> ");

Returns to the previous page.

V:

<A href = <% = request. servervariable ("http_Referre) %>

<Asp: image id = "imageback" visible = true "imagurl =" Previous Page "runat =" server "/> </a>

VI:

Response. Write ("<script> alert ('prompt information'); history. back () </script> ");

Response. Write ("<script> alert ('prompt information'); top. location. href = '" + PageURL + "' </script> ")

Response. Write ("<script> alert ('prompt information'); window. location. href = '" + PageURL + "' </script> ");

Response. Write ("<script> alert ('prompt information'); window. location = window. location; </script> ");

Use Javascript to implement and use Response. redirect () is a little different. If you want to retain the data you entered when using a daily form, you need to use history. go (); you can use reponse. redirect.

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.