刷新页面 [英] refesh page

查看:138
本文介绍了刷新页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经使用C#和ASP.NET创建了一个aspx页面,并在上面放了一个按钮.并在此按钮的Click事件中(如果我正在数据库中插入一些数据),单击后,如果用户刷新页面,则再次触发click事件,从而导致数据再次插入数据库,以停止在浏览器刷新时触发页面上的事件

i have created a aspx page using C# and ASP.NET and have put a button on it. And in the Click event of this button if i am inserting some data in database , after click if user refresh the page than click event gets fired again resulting data insertion to database again, to stop events on the page getting fired on browser refresh
which code i have to put in my page?

推荐答案

看看本文.这应该可以帮助您解决所面临的问题: ASP.Net中的刷新页面问题 [ ^ ]

这是完成操作的各种方法之一.其他方法可能是验证最后输入的数据,然后在继续操作之前进行比较和提示.
Have a look at this article. This should help you out in handling the issue you are facing: Refresh Page Issue in ASP.Net[^]

This is one of the various ways it was done. Others could be to verify the data entered last, compare and prompt before moving ahead.


尝试:

if(!IsPostBack){
//要插入的代码
}
Try:

if(!IsPostBack){
//Code to insert
}


您可以使用以下解决方案之一来解决此问题
1.上传成功后.响应.重定向到同一页面.
2.使用Javascript禁用F5,然后单击鼠标右键.(用户仍然可以从工具栏/菜单栏刷新)
3.使用hiddenfield检查请求是否来自buttonclick或刷新按钮
You can use one of following solutions to solve this problem
1. After Upload is sucessfull. Response.Redirect to same page.
2. Use Javascript to disable F5 and right click.(User can still refresh from toolbar/menubar)
3. Use hiddenfield to check whether request came from buttonclick or refresh button


这篇关于刷新页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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