Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Refresh the page after a postback action in asp.net

I have command button added in my asp.net grids. After performing an action using that button, we refresh the grid to reflect the new data. (basically this action duplicates the grid row).

Now when user refresh the page using F5, an alert message is displayed (to resend the information to server) if we select "retry", the action is repeated automatically.

I know this is a common problem in asp.net, how can we best handle this?

like image 415
MOZILLA Avatar asked Feb 16 '09 13:02

MOZILLA


People also ask

Is page refresh on PostBack?

A refresh mean a complete reload of the page, without any form data. This is essentially an HTTP GET . A post back is when the page is posted to itself (through the form action="" ). This is essentially an HTTP POST .

How do you refresh a razor page?

After a Form submission, when User refreshes the Page or presses the F5 key, the Browser tries to re-post the information again to the Browser and if the User responds as Retry then it could lead to duplicate entries in the Database.

How refresh the page in VB net?

Response. Write("<script type='text/javascript'> setTimeout('location. reload(true); ', timeout);</script>"); Put the above code in button click event or anywhere you want to force page refresh.

How do you prevent button click event firing when a page is refreshed?

One way to prevent this from happening is to use Response. Redirect("same_page") to the same page after the event logic. This will force the page to reload and thereafter doing any further page refreshes would not call the button click event.


2 Answers

Search for GET after POST - http://en.wikipedia.org/wiki/Post/Redirect/Get - basically, redirect to the current page after you're finished processing your event.

Something like:

Response.Redirect(Request.RawUrl)

like image 119
chris Avatar answered Sep 18 '22 03:09

chris


If you think you don't need postback paradigm, you might want to look at ASP.NET MVC.

like image 21
mmx Avatar answered Sep 20 '22 03:09

mmx