Avoiding a refresh in ASP.NET 2, how-to?

  • Thread starter Thread starter Brian Simmons
  • Start date Start date
B

Brian Simmons

Hi all,

I come from a ColdFusion background, and the majority of the time, here's
how we processed a page:
1) The Data entry page would have a submit button which would post to an
action page
2) The action page would do the validation and database processing, if
successful, the action page would <cflocation> (similar to a
Response.Redirect or Server.Transfer) to a display page.

If the end-user hit F5 or Refresh on the toolbar of the browser, the final
display page would be refreshed, not the original page or the action page.
This prevented the database processing from occuring twice.

Note: the original data entry page DOES NOT post back to itself, like in
ASP.NET.

So, now that I'm on the ASP.NET 2 bandwagon, I'm curious as to how to
prevent the double database processing happening if/when a user clicks
F5/Refresh.

I'm noticing that on pages which I have an insert, delete, or updating going
on, the user submits the changes, and then when the page comes back...If the
user clicks Refresh/F5, then the page (will show the postback warning which
most users don't read and/or understand) will attempt to do the database
action again, thus causing potential problems.

Suggestions?

Thanks,
Brian
 
You might also try:

if (!Page.IsPostback)
{
.......code that you only want to process once......
}
 
That won't help in the situation described by the OP, since if the last
action was an HTTP POST and you hit Refresh on your browser, it's going to do
the POST again.
Peter
 
Hi Brian,

For ASP.NET web page model, if you still want to prevent duplicated submit
of page postback processing, you can still use the same way like what you
do in code fusion. You can let the ASP.NET page postback(when click button
or other postback control) as normal, and do the server-side processing in
page/control's postback event, however, after the processing code , you add
an additional statement to redirect the page. e.g.

Response.Redirect("the page itself....")

Thus, after the page is successuflly finishing the postback, it won't
suffer from duplicated submit issue. How do you think?

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead


This posting is provided "AS IS" with no warranties, and confers no rights.
 
Hi Steven,

Thank you for the reply. I implemented the solution exactly as you
specified. Works like a charm.

Thanks,
Brian
 
Back
Top