如何防止用户使用asp.net Web表单在数据库中插入重复记录。 [英] how to prevent user to insert duplicate records in database using asp.net web form.

查看:209
本文介绍了如何防止用户使用asp.net Web表单在数据库中插入重复记录。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,



我使用from将数据插入数据库。



when from是由用户填写并连续按下提交按钮然后连续插入数据库中的一堆重复行。



如何阻止用户提交重复数据。



当我使用system.thread.sleep(3000)点击一次后禁用提交按钮时;然后它不执行页面验证。



如果连接很慢,用户在回发发生之前多次点击,然后你得到多个插入...我试过在插入按钮上使用OnClientClick =this.disabled = true但如果存在验证问题,则用户必须先修复它们,然后禁用插入按钮。





请建议我必须解决这个问题。



谢谢

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

推荐答案

首先,如果可能的话,你应该防止重复的记录写入数据库(您可以随时检查是否存在具有完全相同内容的记录并返回错误)



您说如果您在点击时禁用该按钮并且存在验证问题插入按钮是否已禁用?



如果存在验证问题,您是否可以不启用按钮?



所以;



点击 - 禁用按钮以防止再次点击

验证错误 - 再次启用按钮。



顺便说一句,我个人更喜欢使用整个表单而不仅仅是按钮。
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.


你可以使用Page.Valid进行提交按钮点击事件,如果通过验证,那么只有



禁用控件。



您也可以参考使用GetPostBackEventReference方法的链接。



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



尝试并还原。



希望这有助于......
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...


这篇关于如何防止用户使用asp.net Web表单在数据库中插入重复记录。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆