避免多次保存操作

编程入门 行业动态 更新时间:2024-10-10 11:25:32
本文介绍了避免多次保存操作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我有一个带有保存按钮的ASPX表单.用户输入交易数据并将其保存,保存时该数据将不会被清除并保持不变,只有页面中来自隐藏字段DB的页面中更新了TransactionID(PrimaryKey Value). 一切正常,除非我输入新数据并无意中多次单击保存"按钮,然后相同的数据被多次保存在数据库中,甚至覆盖了DAO中的重复检查.

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.

推荐答案

在插入之前,请检查表中是否存在所有字段(如果存在)意味着退出方法,否则保存数据 例如: 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 } } }

或 插入数据后,禁用保存"按钮 btnsave.visible = false;

or after inserting data disable the save button btnsave.visible=false;

成功保存数据后,取出该记录唯一的值并将其保存在viewstate/hiddenfield中.现在,每次单击保存都将检查此值,并将其与表单上存在的唯一值进行比较.如果它们相同,则将其丢弃;如果它们不同,则将其保存为新数据.另外,如果viewstate值为null ,则必须保存它,因为这将意味着该页面是第一次打开. 我希望这将有所帮助.告诉我我是否理解不正确.我将尝试改进解决方案. 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.

,当您单击savebutton时,在保存数据时禁用整个页面,并在保存数据后启用该页面.您可以使用div来实现. 如果您想以这种方式解决您的问题,我将通过代码进行解释.如果是,则除了评论. 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.

更多推荐

避免多次保存操作

本文发布于:2023-10-19 17:46:34,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1508298.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:操作

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!