复选框控制按钮启用的属性 - ASP.NET [英] Checkbox to Control Button Enabled Property - ASP.NET
问题描述
我想知道我怎么能基于检查复选框的值控制按钮的已启用属性:
I would like to know how I can control the 'Enabled' property of a button based on the 'checked' value of a checkbox:
<asp:CheckBox ID="chkEnableButton" runat="server" />
<asp:Button ID="btnLoadForm" runat="server" />
我可以在服务器端做到这一点很容易 - 但我需要这只能在客户端完成,这意味着JavaScript的。请问OnCheckedChanged属性允许我这样称呼一些JavaScript来做到这一点....还是严格在$ C $调用处理器C-后面?
I can do this very easily on the server side - but I require this to be done on client side only, meaning JavaScript. Would the OnCheckedChanged attribute allow me to call some JavaScript to do this....or is it strictly for calling a handler in the code-behind?
只是为了澄清,当复选框被选中,按钮被启用...当该复选框被选中的按钮被禁用。
Just to clarify, when the checkbox is checked, the button is enabled... when the checkbox is unchecked the button is disabled.
推荐答案
使用Javascript:
Javascript:
<script type="text/javascript">
function checkButt(obj) {
document.getElementById('<%=btnLoadForm.ClientID%>').disabled = !obj.checked;
}
</script>
Web控件:
<asp:CheckBox ID="chkEnableButton" runat="server" OnClientClick="checkButt(this);" />
<asp:Button ID="btnLoadForm" runat="server" />
这篇关于复选框控制按钮启用的属性 - ASP.NET的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!