473,405 Members | 2,187 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

preventing duplicate data entry on RELOAD

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
5 2940
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
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
> 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
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
> > 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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: marx | last post by:
I have a bit of a problem and any help would be much appreciated. Problem: I have two dropdown list boxes with same data(all data driven). These are used for two separate entries. For every...
4
by: Drew | last post by:
I have a permission tracking app that I am working on, and I have made the insert page for it. I am having issues on how to prevent duplicates from getting entered. Currently the interface for...
1
by: Randy | last post by:
I am using Approach 9.8 and have set up a appointment database with the following fields. DATE, TYPEACTION, TIME, WORKER LASTNAME FIRSTNAME I do not want my clerical staff to be able to key in...
3
by: ColinWard | last post by:
I am using the following code to validate that the person that is being entered into the database does not already exist. However wnem I test it by entering myself as a contact(I first checked that...
5
by: Manish | last post by:
The topic is related to MySQL database. Suppose a table "address" contains the following records ------------------------------------------------------- | name | address | phone |...
1
by: pcnorb | last post by:
I have a form, pulling data from a Products table that has many fields that do lookups to other tables. These are in a one-to-many relationship to a pk in each of said tables. I'd like to be...
7
by: chowdary | last post by:
I am developing a PHP-mysql database. It is noted that when the browser window is refreshed the data is inserted again in the database. unfortunately there is no unique keys that I can use to...
9
by: rjshrader | last post by:
I have a table (tblStatus) with three fields (CustomerID, StatusType and StatusDate). I use an unbound form with three text boxes to enter data into the table when a command button (cmdSave) is...
4
by: AXESMI59 | last post by:
have a project in which I am entering Serial Numbers and Date codes into a Combo box. Serial numbers are all different. However, they could each have the same Date Code. Each Serial Number has a...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.