Click here to Skip to main content
15,897,032 members
Please Sign up or sign in to vote.
2.40/5 (2 votes)
See more:
Hello all,

I am using a from to insert data into database.

when from is fill by user and press on submit button again and again continuously then a bunch of duplicate rows inserted into database.

How can i prevent user to submit duplicate data.

When i am disabling the submit button after one click by using system.thread.sleep(3000); then it does not perform validation of page.

if the connection is slow the user click multiple times before the Postback happens and then you get multiple Inserts... I tried using OnClientClick="this.disabled=true" on the Insert button but if there are validation problems the user will have to fix them first and then the Insert button is disabled.


Please suggest what i have to do resolve this.

Thanks
Posted
Updated 3-Dec-13 8:41am
v3
Comments
Maciej Los 3-Dec-13 15:34pm    
What is your query and code behind (onClick)?

Firstly, you should prevent duplicate records being written to the database if at all possible (you can always check if a record with exactly the same contents exists and return an error)

You say that if you disable the button on clicking and there are validation problems the insert button is disabled?

Well can you not enable the button if there are validation problems?

So;

On Click - disable the button to prevent another click
On Validation Error - enable the button again.

Incidentally, I personally prefer disbling the whole form rather than just the button.
 
Share this answer
 
You can use Page.Valid for the submit button click event , and if passes validation then only

Disable the control .

You may refer the link which uses GetPostBackEventReference method approach too.

http://forums.asp.net/t/1395392.aspx[^]

Try and revert.

Hope this helps...
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900