按钮禁用问题 [英] Button disable problem
本文介绍了按钮禁用问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
protected void Button1_Click(object sender, EventArgs e)
{
Button1.Enabled = false;
try
{
// put your code here
}
finally
{
Button1.Enabled = true;
}
}
我写了这段代码,仍然没有禁用按钮,并启用了
i wrote this code still button not disable and enable why
推荐答案
,因为您使用了finally块,这就是为什么按钮未禁用的原因.
如果您使用try-catch-finally
然后最终将在是否发生错误且代码发生相同的情况下执行.
阅读此内容-
http://msdn.microsoft.com/en-us/library/dszsf989%28v = vs.80%29.aspx [ ^ ]
because you used finally block, that''s why button is not disabling.
if you are using try-catch-finally
then finally will be executed if error occurs or not and the same happening to your code.
Read this -
http://msdn.microsoft.com/en-us/library/dszsf989%28v=vs.80%29.aspx[^]
您可以在finally块中启用按钮.
You enable your button in finally block.
finally
{
Button1.Enabled = true;
}
使用
use
try
{
}
catch
{
Button1.Enabled = true;
}
Button1.Enabled = false;
try
{
// put your code here
}
catch
{
Button1.Enabled = true;
}
这篇关于按钮禁用问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文