禁用asp.net按钮将禁用按钮的验证 [英] Disabled asp.net button disables validation for button
问题描述
我有一个aspx页面,其中包含一个复选框和一个按钮.默认情况下,该按钮处于禁用状态,直到用户选中该复选框.当我向按钮添加属性enabled ="false"时,它似乎删除了验证.启用按钮后,我仍然希望验证工作.这是不同部分的代码和标记.
I have an aspx page that contains a checkbox, and a button. The button is disabled by default until the user checks the checkbox. It looks like when I add the attribute enabled="false" to the button, it removes the validation. When the button is enabled, I still want the validation to work. Here is the code and markup for the different parts.
复选框:
<asp:CheckBox runat="server" ID="termsCheckBox" />
<label style="display: inline;">
I agree to the Terms & Conditions</label>
按钮:
<asp:Button runat="server" ID="registerButton" OnClick="registerButton_Click1"
Text="Register" Enabled="false" ValidationGroup="accountValidation" />
jQuery:
<script type="text/javascript" language="javascript">
$(document).ready(function () {
$('#<%=termsCheckBox.ClientID %>').click(function () {
var checked = $(this).val();
if (checked != undefined)
$('#<%=registerButton.ClientID %>').removeAttr('disabled');
else
$('#<%=registerButton.ClientID %>').attr('disabled', 'disabled');
});
});
</script>
推荐答案
我认为,如果您启用/禁用了CheckBox服务器端事件而不是客户端上的按钮,那么它将起作用,因为相关的客户端验证代码将是生成以为按钮的ValidationGroup运行
I think it would work if you enabled/disabled the button on the checkBox server-side event rather than client side since the associated client-side validation code will be generated to run for ValidationGroup of the button
这篇关于禁用asp.net按钮将禁用按钮的验证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!