Search code examples
ispostback

Refresh of Page set PostBack = true


I have one of a aspx page in my asp.net project which has a button control after clicking on the button and then refreshing the page using F5 key or refresh button of the browser, instead of setting IsPostBack property to false, it is setting it to true.

Can anyone help me out of this?


Solution

  • Clicking the button triggers a HttpPost of the form and it's posted to the same page, which is what's called a post back. Refreshing the page triggers the last executed action, which in this case was a post. Most browsers warn the user about this when they refresh a posted page.

    In case you don't want this behaviour you have to make sure that you perform a get operation after the post (the so called "Redirect after post/Get after post"-technique).

    One way of achieving it is to end the post back action with:

     Response.Redirect(Request.RawUrl);