将Button置为Enabled=False 后再置为true后引发的问题
我的代码如下:
<form id= "form1 " runat= "server ">
<asp:TextBox ID= "TextBox1 " runat= "server "> </asp:TextBox>
<asp:RequiredFieldValidator ID= "RequiredFieldValidator1 " runat= "server " ControlToValidate= "TextBox1 "
ErrorMessage= "不能为空 "> </asp:RequiredFieldValidator>
<asp:button id= "btnSave "
usesubmitbehavior= "true "
Enabled= "false "
text= "Save "
runat= "server " onclick= "Button1_Click " />
<asp:button id= "btnEnabled "
usesubmitbehavior= "true "
text= "Enabled "
onclientclick= " return Enabled() "
runat= "server " onclick= "Button1_Click " />
</form>
<script type= "text/javascript ">
function Enabled()
{
document.getElementById( " <%= btnSave.ClientID%> ").disabled = false;
return false;
}
</script>
这样操作后点击Save按钮后验证控件虽然起作用,但是刷新了页面,走了一遍后台代码,我想一定是document.getElementById( " <%= btnSave.ClientID%> ").disabled = false;没有将btnSave的状态完全恢复,该怎么解决,请高手帮忙
[解决办法]
如果后台disable设为False。到前台这个按钮就已经不存在了。你再想用脚本让display=True是不可能的,会提示 '对象不存在 '
关于True和False
要么,都用后台控制
要么,都用前台控制