By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,652 Members | 1,358 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,652 IT Pros & Developers. It's quick & easy.

preventing duplicate data entry on RELOAD

P: n/a
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
Nov 19 '05 #1
Share this Question
Share on Google+
5 Replies


P: n/a
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.

"Darrel" wrote:
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

Nov 19 '05 #2

P: n/a
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

"Kaustav" <Ka*****@discussions.microsoft.com> wrote in message
news:86**********************************@microsof t.com...
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.

"Darrel" wrote:
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

Nov 19 '05 #3

P: n/a
> 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
Nov 19 '05 #4

P: n/a
Darrel wrote:
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.


"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!
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

Nov 19 '05 #5

P: n/a
> > 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!


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
Nov 19 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.