Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C# ASP
I have a ASPX form with a Save Button. User enters transaction data and saves it on saving the data will not get cleared and remain intact and only TransactionID(PrimaryKey Value) is updated in the page from DB which is a hidden field.
 
Everything works fine except when I enter new data and accidentally clicked on Save Button multiple times, then the same data is getting saved multiple times in the DB even overriding the Duplication checking in my DAO.
 
Do anyone have a solution for fixing this.
Posted 29-May-12 19:05pm
Comments
JimJos at 30-May-12 1:16am
   
Data getting added as new record or existing record is updated?
Rajesh Kariyavula at 30-May-12 1:26am
   
The same record gets inserted multiple times
JimJos at 30-May-12 1:34am
   
If you primary key constraint properly set insertion will fail right? Are you using autoincrement as primary key - then it won't fail
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 3

are you using UpdatePanel. its most likely that on IsPostBack, you are not refreshing your page or you are not setting the new values into the fields inside IsPostBack body
 
try to debug the page at OnLoad event over page.IsBostBack Method. hope you will reach to the solution.
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

Before inserting check all fields present in table or not if present means exit from the method else save the data
 
ex:
public void save()
{
saldataadapter da=new SqlDataAdapter("select *from sample",con);
dataset ds=new dataset();
da.fill(ds);
for(int i=o;i<ds.tables[0].rows.count;i++)>
{
if(txtname.text==ds.tables[0].rows[i][1].tostring() &&txtaddr.text==ds.tables[0].rows[i][2])
{
response.write("Data exist");
 
}
else
{
//write insert logic here

}
}
}
 

or
 
after inserting data disable the save button
 
btnsave.visible=false;
  Permalink  
v2
Comments
Rajesh Kariyavula at 30-May-12 1:52am
   
This will not work for me we are using nHibernate along with spring.net not the ADO.Net, anyways thanks for your answer
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

When your data is saved successfully, take out the value that is unique for that record and save it in the viewstate/hiddenfield. now every time the save is clicked check for this value and compare it with the unique value that exist on form. if they are same then discard it, if they are different then save it as you have new data. also if the viewstate value is null you have to save it as it would mean this page is opened for first time.
 
I Hope this will help. tell me if I understood incorrectly. i will try to improve the solution.
  Permalink  
Comments
Rajesh Kariyavula at 30-May-12 2:04am
   
Even before the HiddenField value is updated multiple records gets saved.
 
Suppose I pressed on Save 3 times then 3 Save operations are firing Which will call a WCF Service Method and that WCF service method calls a RepoMethod where Duplication is checked and data is saved using nHibernate.
 
Three records will get inserted into the table with same data and the hidden field will get the last record ID
Rahul Rajat Singh at 30-May-12 2:08am
   
Here is an idea. when the user hits the save button disable it for some time and re-enable it when the save is successful and you have kept that value in your viewstate. i guess the button will be disabled for half a second and that should be fine. also you can show the text of button as "saving..." while it is disabled that would be good from usability standpoint too.
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 4

when you click on savebutton then diable the whole page while data save and after save data enable the page. you can do it by using div.
if you want to solve your problem in this way than i will give explain it by code. if yes than comment.
  Permalink  

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



Advertise | Privacy | Mobile
Web03 | 2.8.140821.2 | Last Updated 30 May 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100