preventing duplicate data entry on RELOAD

D

Darrel

I have a web form that inserts a record into a DB. This function is called
from the button_click subroutine.

After the record is inserted, I show/hide some different panels and let the
page postback.

The problem is that if a person reloads this page after submitting, a new
record is inserted into the DB.

Short of doing an actual compare query prior to entering the new record, or
redirecting to a new page, is there a way to prevent this from happening?

-Darrel
 
G

Guest

Hi Darrel,

one way to avoid this is to clear all values in the cache after postback.
You can use the Javascript doPostBack function for the same. Place a label
control "lblPostback" at the end of the page. Next place the following code
in the respective events as mentioned below:

Page Load Event:

If Page.IsPostback Then
lblPostback.Text = ""
End If

Button Submit Event:
On the button submit event, after all the processing has been done, place
the following code snippet-

lblPostback.Text = "<script>javascript:__doPostBack('','');</script>"

HTH.

Kaustav Neogy.
 
J

Johann MacDonagh

Kaustav's suggestion will work, but it will cause an extra trip to the
server. You could also use the Page's RegisterStartupScript method to invoke
a Javascript method at the Page's load.

One thing you should ask yourself is, would it be possible to redirect the
user to a different page (using Response.Redirect), and achieve the same
results? For example, if you have a Form that has a set of TextBoxs and a
button which will insert the data, you can simply redirect the user to the
same page, which will get rid of any PostBack issues (such as having the
non-user-friendly "The page cannot be refreshed..." confirm box IE has).
Perhaps you could use a QueryString that would tell the page to use
information from the newest submitted record. I'm not sure of your
situation.

Hope I could help,
Johann MacDonagh
 
D

Darrel

I'm not sure of your situation.

I have a page with two panels. One panel is the form. One panel is the
'success' confirmation.

On completion of a succesful submit, I hid the form panel and show the
success panel.

When a person reloads the page, though, it resubmits the data. I was
confused because the data is only submitted via the button_click
function...not the page_load function.

However, I think simply adding a flag on submit is the way to go...but yea,
it looks like a roundtrip to the server.

I suppose redirectly to another page is perhaps a better idea. However, I
have dozens of these submit/confirm combo pages so that may have to get put
off and added to the bottom of the to-do list.

-Darrel
 
H

Hans Kesting

Darrel said:
I have a page with two panels. One panel is the form. One panel is the
'success' confirmation.

On completion of a succesful submit, I hid the form panel and show the
success panel.

When a person reloads the page, though, it resubmits the data. I was
confused because the data is only submitted via the button_click
function...not the page_load function.

"reload" means "execute the same action that originally gave you this page",
so the browser will act (submit the form) as if that button was pressed,
using the values that were previously on the form. So a resubmit of the
same data is correct (though unwanted :) ) behaviour.
However, I think simply adding a flag on submit is the way to
go...but yea, it looks like a roundtrip to the server.

But: it will use the *previous* values!
 
D

darrel

However, I think simply adding a flag on submit is the way to
But: it will use the *previous* values!

Ah...duh. You're right. Hmm...crap...this seems like something .net should
be able to handle for you ;o)

I guess it looks like a final page redirect and/or checking for duplicate
records in the DB are the only answer? (Though the javascript solution might
work...though I'd rather avoid javascript for checkig data integrity).

-Darrel
 

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

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,014
Latest member
BiancaFix3

Latest Threads

Top