【问题标题】:asp.net radio button does not post back when page is not valid当页面无效时,asp.net 单选按钮不会回发
【发布时间】:2012-01-04 00:02:33
【问题描述】:
<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 asp.net validation


    【解决方案1】:

    您应该转向基于 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" />
    

    【讨论】:

    • 感谢 steve,因为在我的情况下,页面验证已经触发并且页面无效,因此验证不起作用。我试过 jquery show and hide 但问题是即使控件被隐藏,验证仍然会触发。
    • 我只是处理了页面上的验证切换并做了一个 javascript 来完成这项工作,关闭了自动回发并且它工作了。
    猜你喜欢
    • 2018-10-13
    • 1970-01-01
    • 1970-01-01
    • 2011-06-14
    • 2020-02-11
    • 2011-09-28
    • 2014-06-15
    • 1970-01-01
    • 2020-12-10
    相关资源
    最近更新 更多