简体   繁体   中英

How to empty ASP.net postback cache?

I just read What is a postback?

I have an asp.net webform on which I click a button to fill server side C# variables. If I am correct this occurs by an HTTP POST (a postback since I resend the user supplied data with the webform back to the server using the body of the HTTP request)

When the server recieves the postback, it will send some instructions bac to the client (for instance "display an alert message").

My problem here is that when I refresh (F5) the webform, what ever action that was performed last is reexecuted. Hence, a postback is reexecuted when I refresh the page, thus triggering a response from the server.

How can I disable this behavior ? By this I mean that how could hitting F5 just reload the page as if it was the first time (I guess all my code behind variables will be restoredto default too...)

This is default browser behavior. F5 will always trigger a repost if the form was submitted (PostBack).

You can get around this behavior by redirecting to the same page again after a PostBack

Response.Redirect(Request.RawUrl, false);

But if you use this, you cannot get a response to the client like you normally would. Only setting a Session before the redirect and then deal with it on the page after redirect would be the only way to get a response from the server to the client.

Better is making sure a repost will not create any problems, like duplicate database entries etc.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM