Method 1:
Private void page_load (Object sender, system. eventargs E)
{
Viewstate ["submittimes"] = convert. toint32 (viewstate ["submittimes"]) + 1;
If (! Page. ispostback)
{
Viewstate ["submittimes"] = 1;
}
}
Page:
<Input type = "button" value = "button" onclick = 'History. Go (-<% = (INT) viewstate ["submittimes"] %>) '>
Method 2:
<A href = <% = request. servervariables ("http_referer") %>
<Asp: Image id = "imgcancel" visible = "false"
Imageurl = "images/cancel. GIF"
Alternatetext = "cancel current operation" runat = "server"/>
</A>
Method 3:
In one example application of Microsoft, (I forgot the name)
Using the following method
In page_load
If (! Ispostback)
{
Viewstate ["urlreferrer"] = request. urlreferrer. tostring ();
}
For go back button click
Private void btngoback_click (Object sender, system. eventargs E)
{
Response. Redirect (string) viewstate ["urlreferrer"]);
}
The problem is in some cases, request. urlreferrer will be null if you use Firewall
Method 4: ASP. NET returns to the previous page and refreshes the page.
Recently, I am working on a website. After adding, deleting, or modifying data, I want the user to go to another page to show that the operation was successful and then return to the original page. Start with history. Go (-1). This will return, but the original page is not refreshed. Because the pages to be returned are not the same, you cannot use the URL-Specific Method to return the results. You still need to obtain the URL of the previous page. If you can see response. Redirect (request. servervariables ["http_referer"]) on the Internet, you can try it and the result will not work. Baidu only knows that the value cannot be normally taken in many cases. I use response. request. servervariables ["http_referer"] is null. It seems that you have to find another way to continue Baidu. We can see that request. urlreferrer is used. Based on the searched method, the system finally successfully returns the result and refreshes it ~~
ProgramCode
Protected void page_load (Object sender, eventargs E)
{
If (! Ispostback)
{
If (request. urlreferrer! = NULL)
Viewstate ["urlreferrer"] = request. urlreferrer. tostring ();
}
}
Protected void button#click (Object sender, eventargs E)
{
Response. Redirect (viewstate ["urlreferrer"]. tostring ());
}
The following is a description of the value of request. servervariables.
In the following cases, the request. servervariables ("http_referer") is obtained from the address bar of the browser:
1. directly use
2. form submitted with submit or (postorget)
3. the form submitted using JScript (postorget)
let's take a look at the request. servervariables ("http_referer") cannot be set properly:
1. link from favorites
2. click 'homepage' or custom address
3. use location of JScript. hreforlocation. replace ()
4. enter the address in the browser
5. <% response. redirect %>
6. <% response. addheader %> or redirect
7. load address with XML