Brief analysis: This uses HTML controls, and calls a method in javascript through an onclick event. This is the simplest"/> Brief analysis: This uses HTML controls, and calls a method in javascript through an onclick event. This is the simplest">

Home >Backend Development >C#.Net Tutorial >What are some examples of how to implement asp.net to return to the previous page?

What are some examples of how to implement asp.net to return to the previous page?

零下一度
零下一度Original
2017-06-23 16:20:251339browse

In fact, to realize the function of returning to the previous page, JavaScript is mainly used.

One:

In the source code in aspx of ASP.net

Brief analysis: This uses HTML control. It only needs to call a method in javascript through an onclick event. This is the most It’s simple, and it also applies to static pages, ASP pages, etc.

2:

Use Response.write

If you have a certain understanding of ASP, then you can use it. Response.write will be familiar to you. The first method is to implement it directly in the HTML page, while this is implemented in the background environment (this statement does not seem to be very standardized, haha)

Response.write (")

Why should the value of -2 be used here? I personally think it is like this: Because on the page in asp.net, when you press a button Finally, because page.postback will be implemented in the page, the page is actually refreshed twice. What we want is the first time, so...

三:

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

Add

if(!IsPostBack) to page_load

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

And in the return button event

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

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

四:

This method is probably rarely used by people, but I tried it It’s pretty good after a while.

Enter in the button’s onClick event

this.RegisterClientScriptBlock("e", "");

You can also return to the previous page

五:

Six:

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

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

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

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

There is a little difference between using Javascript and using Response.redirect(). If you want to keep the fields you fill in when using the form data, then use history.go(); if you just return it directly without doing any operations, you can use response.redirect().

The above is the detailed content of What are some examples of how to implement asp.net to return to the previous page?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn