Click here to Skip to main content
15,891,253 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have disabled the Submit button on my web page to prevent users from submitting it multiple times. I want to save user data only once into the database when user hit the submit button.
Most of the time it works fine but sometime I ended up having multiple entries of same records in database. Is there anything that I am doing wrong here ? Any other suggestion ?

C#
StringBuilder sbValid = new StringBuilder();

            sbValid.Append("if (typeof(Page_ClientValidate) == 'function') { ");

            sbValid.Append("if (Page_ClientValidate('RequiredFields') == false) { return false; }} ");

            sbValid.Append("this.value = 'Please wait...';");

            sbValid.Append("this.disabled = true;");


            //GetPostBackEventReference obtains a reference to a client-side script function that causes the server to post back to the page.

            sbValid.Append(this.Page.GetPostBackEventReference(this.btnSubmit));

            sbValid.Append(";");

            this.btnSubmit.Attributes.Add("onclick", sbValid.ToString());


RequiredFields is the name of validation control group on that page.

The worst thing about this situation is I cannot recreate the issue. It is very random. :(
Posted
Updated 29-Sep-10 16:57pm
v2

Hi,

What about refresh button?! you have disabled your submit button but user can still press refresh button! I think your problem might be because of Refreshing page or pressing F5!
check it out.
 
Share this answer
 
Comments
virang_21 29-Sep-10 22:32pm    
The web application is used by 400 agents so may be one of them doing something like that is possible.

Is there any programmatic way to prevent this ?

Alternative for me is to check for duplicate records in database and give admin option to delete them but I want to prevent this behavior of multiple records in database.
aidin Tajadod 29-Sep-10 23:00pm    
There is actually no way to detect refresh ( Although there are some way but none of them are trustful).
So I think checking with database might be the best way.
Urvi Chhatbar 5-Jan-23 7:32am    
hello
hello,

We can disable the button during postback. This article might help

Disable an ASP.NET Button Control During Postback with an AJAX Loading Background Image[^]
 
Share this answer
 
For avoiding multiple form submits,
Avoid Multiple Form Submits[^]

And also do,

1. Add validation business rules in class level or DB level.
2. After saving data, redirect the page so that you can prevent the duplicate entry on F5/browser refresh.
 
Share this answer
 
Hi,

if the user is clicking the multiple times of save button in ur page, then make a condition in ur storedprocedure that the same id or name will not be duplicants while inserting..

Regards,
S.Inayat basha.
 
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