在刷新运行asp.net停止按钮事件 [英] asp.net stop button event running on Refresh
问题描述
我有在我的C#单击事件的按钮。这个伟大的工程。然而afetr pressing F5刷新页面,我注意到按钮事件。出现这种情况我点击F5每次。如果(page.IsPostBack)我已经添加和方法仍然运行。
I have a button that has click event in my C#. This works great. However afetr pressing F5 to refresh the page I noticed the button event is fired. This occurs every time I click F5. I've added if(page.IsPostBack) and the method still runs.
有没有办法从烧制F5刷新按钮被点击时停止这种方法吗?
Is there any way to stop this method from firing when the F5 Refresh button is clicked?
谢谢!
推荐答案
如果您有需要运行一次一个页面,你应该在你的code是$ P $实现逻辑pvents运行多个相同的方法倍。在伪code:
If you have a page that needs to be run once, you should implement logic in your code that prevents the same method from running multiple times. In pseudo-code:
if (canExecuteMethod()) {
executeMethod();
} else {
displayMessageThatMethodCannotBeExecuted();
}
例如,您可以检查与会话变量canExecuteMethod()
,它返回false时,它不是present和设置 executeMethod()
:
For example, you can check a Session variable with canExecuteMethod()
, which returns false when it is not present and is set in executeMethod()
:
function canExecuteMethod() {
return Session["methodIsExecuting"] == null
|| Session["methodIsExecuting"] == false;
}
function executeMethod() {
Session["methodIsExecuting"] = true;
// ...
}
当然使用Session变量已经它限制,所以你可能要考虑使用一个数据库或者AppSettings的变量,而不是。
Of course the use of a Session variable has it limits, so you might want to consider using a database or AppSettings variable instead.
这篇关于在刷新运行asp.net停止按钮事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!