在页面刷新时插入到DB [英] Insertion to DB while page refreshing
本文介绍了在页面刷新时插入到DB的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
大家好
在我的asp.net项目中,我在Insert语句后使用以下代码,以避免在刷新页面时重新插入数据库的问题< pre lang =c#> Response.Redirect(HttpContext.Current.Request.Url.AbsoluteUri);
有没有其他方法,因为这种方法不适合某些页面。
解决方案
是的选项很少。请看这个链接:
http://csharpdotnetfreak.blogspot.com/2008 /12/detect-browser-refresh-to-avoid-events.html [ ^ ]
检测ASP.NET中的刷新或回发 [ ^ ]
http://www.aspdotnet-suresh.com/2010/04/ detect-browser-refresh-to-avoid-events.html [ ^ ]
http://forums.asp.net/t/1885490.aspx [ ^ ]
刷新ASP.Net中的页面问题 [ ^ ]
并查看此类问题的先前答案
检测浏览器刷新并避免在ASP.Net中触发事件 [ ^ ] />
避免页面刷新时按钮点击事件 [ ^ ]
问题表单点击浏览器的刷新按钮比btn单击事件触发 [ ^ ]
Hi Praveen,
如果你想要做到这一点在asp.net中你可以参考这里 [ ^ ]
如果你想在数据库端检查它,那么你可以使用EXISTS
这样的函数
IF NOT EXISTS ( SELECT ID FROM InsertTableName WHERE ID = ' 要插入的ID')
BEGIN
INSERT INTO InsertTableName VALUES ( 101 ,' 名称');
ELSE
打印 ' 记录已经存在'
希望这对你有所帮助。
问候,
RK
Hi all
In my asp.net project i use following code after Insert statement to avoid the problem of re insertion of values to DB while refreshing the page
Response.Redirect(HttpContext.Current.Request.Url.AbsoluteUri);
is there any other method , because this method is not suitable in some pages.
解决方案
Yes there are few options.please see this links:
http://csharpdotnetfreak.blogspot.com/2008/12/detect-browser-refresh-to-avoid-events.html[^]
Detecting Refresh or Postback in ASP.NET[^]
http://www.aspdotnet-suresh.com/2010/04/detect-browser-refresh-to-avoid-events.html[^]
http://forums.asp.net/t/1885490.aspx[^]
Refresh Page Issue in ASP.Net[^]
and see previous answers of this sort of question
Detect Browser Refresh and avoid Events fire in ASP.Net[^]
Avoid button click event on page refresh[^]
problem form click refresh button of browser than again btn click event fire[^]
Hi Praveen,
If you want to do it in asp.net then you can refer here[^]
If you want to check it in DB side then you can useEXISTS
function like this
IF NOT EXISTS(SELECT ID FROM InsertTableName WHERE ID = 'ID you want to insert') BEGIN INSERT INTO InsertTableName VALUES(101,'Name'); ELSE Print 'Record already exist'
Hope this helps you a bit.
Regards,
RK
这篇关于在页面刷新时插入到DB的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文