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

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
 
V

vcuankitdotnet

You might also try:

if (!Page.IsPostback)
{
.......code that you only want to process once......
}
 
B

Brian Simmons

Thanks Mark, I tried google, but didn't use that keyword: prevent
Muchas gracias!
 
G

Guest

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
 
S

Steven Cheng[MSFT]

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.
 
B

Brian Simmons

Hi Steven,

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

Thanks,
Brian
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,583
Members
45,073
Latest member
DarinCeden

Latest Threads

Top