Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Submit the Form Only Once 2

Status
Not open for further replies.

sunila7

Technical User
Apr 11, 2001
1,087
US
Hi All,

How can I make sure that the form is submitted only once when a save button is clicked on the form.

Right now I have a form on which the user can click on a save button as many times he wants and the data gets duplicated in the database. How can i avoid this?

Thanks for help

Sunil
 
Couple ways you could do this:

1. Add an onClick attribute to the button so that when its clicked, some hidden field on the client side gets assigned to something. You could then have a validator assigned to check the value of that hidden field. When the user clicks the save button once, the field fills. When the user clicks it again, the validator will catch that the field has been filled, and can display a message like "You've already saved this item". Just make sure to clear the field when its a new item to be added

2. Change the way you identify records in the database. I usually let me interfaces double for adding new items and editing existing ones. The difference is that I check to see if there's already a unique id assigned to the object, and if there is then I UPDATE the existing record. if there isn't one, then I INSERT the new one.

Couple options anyway. Its a bit more complicated than just disableing the button...although that may be an option too?

hope I gave some ideas

D'Arcy
 
Hi

I think what I would do is Set the Save button to "Visible = False" so when you do your post back the save button disappears that way they can not send the same data again

Cheers
 
Hi Guys,

jfrost,
Ur first suggestion worked, I created a textbox and on click of the button, I used a javascript fuction to increment its value... and on the server side now Iam checking the value of the textbox, if it is greater than 1 then it doesnt insert into the DB.

Thanks for the inputs, guys


Sunil
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top