您可以使用jQuery。现在,你通常不会看到一个不使用jQuery或Javascript框架的网站。
由于您无法在运行时预测服务器控件ID,因此您希望使用#<%= SearchButton.ClientID %>
。
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
<asp:Button ID="SearchButton" runat="server" Text="Search"
ValidationGroup="SearchRoles" CausesValidation="true"
OnClick="SearchButton_Click" />
<br />
<input type="checkbox" id="DisableButtonCheckBox" />
Check to disable button
<script type="text/javascript">
$(function() {
$("#DisableButtonCheckBox").click(function() {
if (this.checked) {
$("#<%= SearchButton.ClientID %>").prop("disabled", true);
} else {
$("#<%= SearchButton.ClientID %>").prop("disabled", false);
}
});
});
</script>
我个人不喜欢使用ClientIDMode="static"
,除非我没有任何其他选择。
来源
2016-06-14 14:34:51
Win