javascript - 当页面无效时,asp.net 单选按钮不会回发

标签 javascript asp.net validation

<asp:RadioButton ID="rdoComm" runat="server" Text="Business Investment" AutoPostBack="true"
        GroupName="selectionType" OnCheckedChanged="rdoComm_CheckedChanged" />
    <asp:RadioButton ID="rdoRes" runat="server" Text="Real Estate" GroupName="selectionType"
        AutoPostBack="true" OnCheckedChanged="rdoRes_CheckedChanged" />
    <asp:RadioButton ID="rdoBoth" runat="server" Text="Both" GroupName="selectionType"
        AutoPostBack="true" OnCheckedChanged="rdoBoth_CheckedChanged" />

每当我使用“Page_ClientValidate('group')”强制验证时,单选按钮不会回发,但是如果我不使用我提到的方法并将其留给 asp.net 验证,即使页面无效单选按钮仍然回传。

单选按钮不是用于回发,而是用于隐藏和显示页面上的控件。

有什么想法吗?>?

最佳答案

您应该转向基于 javascript 的解决方案...这将避免回发并为用户提供更好的体验。

但如果你不能,只需设置 CausesValidation property单选按钮上的 false :

<asp:RadioButton ID="rdoComm" runat="server" Text="Business Investment" AutoPostBack="true" CausesValidation="false"
    GroupName="selectionType" OnCheckedChanged="rdoComm_CheckedChanged" />
<asp:RadioButton ID="rdoRes" runat="server" Text="Real Estate" GroupName="selectionType" CausesValidation="false"
    AutoPostBack="true" OnCheckedChanged="rdoRes_CheckedChanged" />
<asp:RadioButton ID="rdoBoth" runat="server" Text="Both" GroupName="selectionType"
    AutoPostBack="true" CausesValidation="false" OnCheckedChanged="rdoBoth_CheckedChanged" />

关于javascript - 当页面无效时,asp.net 单选按钮不会回发,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8720413/

相关文章:

c# - ASP.NET MVC 4 和 WYSIWYG 编辑器验证

javascript - 打印编译好的 Handlebars 模板(未填写数据)

javascript - 提交时抛出错误如何允许表单 POST

asp.net - 如何渲染另一个项目的局部 View

asp.net - 无法加载 SQL Server Compact 的 native 组件

jquery - 向左滚动的内联验证

ruby-on-rails - ActiveRecord 未使用 .build 在 has_many 关联上设置外键

javascript - 如何在 Angular 12 中动态加载组件

javascript - Webpack 2 加载、公开和捆绑 jquery 和 bootstrap

Asp.net 站点在同事计算机上显示不同