Implement ASP. Return to the previous page what are the instances?

Source: Internet
Author: User
In fact, to achieve the function of returning to the previous page, the main thing is to use JavaScript.

One:

In the source code of the ASP.

<input type= "button onclick=" Javascript:window.history.go (-1); " Value= "Back to Prev" >

Analysis: This is the use of HTML control, through an onclick event, called a method in JavaScript can be. This is the simplest, also applicable to static pages, ASP pages and so on.

Two:

Using Reponse.write

If you have a certain understanding of ASP, then the Response.Write this east will not be unfamiliar, method one is directly have HTML page implementation, then this is in the background environment implementation (This statement seems not very standard, hehe)

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

<a href= "#" onclick= "Javascript:history.back ();" > Return to Previous page </a>

This is going to take the value of-2, I personally think it is: because in the ASP. NET page, when you press a button, because the page will be implemented Page.postback, actually in this is the refresh of the page two times, we want the first time, so it ......

Three:

Using Response.Redirect () or Server.Transfer ()

Join in the 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 ());

Four:

This method is estimated to be very rare, but I've tried it and it's pretty good.

Enter in the OnClick event of the button

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

Can go back to the previous page

Five:

<a href=<%=request.servervariable ("Http_referre)%>

<asp:image id= "Imageback" visible = True "imagurl=" previous page "runat=" Server "/></a>

Six:

Response.Write ("<script>alert", History.back () </script> ");

Response.Write ("<script>alert"), top.location.href= ' + pageurl + ' </script> ')

Response.Write ("<script>alert"), window.location.href= ' + pageurl + ' </script> ');

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

Using JavaScript to achieve with the Response.Redirect () to achieve a little difference, if you are using the day form to keep the data you fill, it is necessary to use history.go (); If you simply return without doing anything, 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.