下拉列表中的RequiredFieldValidator无法处理提交按钮单击

时间:2017-04-10 22:27:31

标签: c# asp.net requiredfieldvalidator validationgroup

我有一个下拉列表的RequiredFieldValidator。两者都在UpdatePanel内。单击提交按钮时,不会从下拉列表中验证用户选择。请指导我错过的内容。

   <asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<div id="divFilter">
    <asp:UpdatePanel ID="uplMain" runat="server">
        <ContentTemplate>
            <asp:PlaceHolder ID="PlaceHolder1" runat="server">
                <table>
                    <tr>
                        <td valign="top">
                            <table>
                                <tr>
                                    <td>
                                        <asp:CheckBox ID="chkBusiness" runat="server" Text="Business Division" CssClass="chkbox" />
                                    </td>
                                    <td>
                                        <asp:DropDownList ID="ddlBusiness" runat="server" AppendDataBoundItems="true" AutoPostBack="true"
                                            CausesValidation="True" OnSelectedIndexChanged="ddlBusiness_SelectedIndexChanged"
                                            ValidationGroup="grpSubmit" Width="350px">
                                            <asp:ListItem Selected="True" Value="-1">--- SELECT ---</asp:ListItem>
                                        </asp:DropDownList>
                                        <asp:RequiredFieldValidator ID="rfvBusiness" runat="server" ControlToValidate="ddlBusiness"
                                            ToolTip="Please select a Business." ErrorMessage="*" CssClass="required" Display="Dynamic"
                                            ValidationGroup="grpSubmit" Enabled="false">
                                        </asp:RequiredFieldValidator>
                                    </td>
                                </tr>
                            </table>
                        </td>
                    </tr>
                </table>
            </asp:PlaceHolder>
            <hr size="1" />
            <div style="text-align: center">
                <table style="width: 10%">
                    <tr>
                        <td>
                            <asp:Button ID="btnHome" runat="server" Text="Home" OnClick="btnHome_Click" CssClass="btn" />
                        </td>
                        <td>
                            <asp:Button ID="btnSubmitReport" runat="server" Text="Submit" OnClick="btnSubmitReport_Click"
                                ValidationGroup="grpSubmit" CssClass="btn" />
                        </td>
                    </tr>
                </table>
            </div>
        </ContentTemplate>
    </asp:UpdatePanel>
</div>

1 个答案:

答案 0 :(得分:0)

尝试将 RequiredFieldValidator 元素中的已启用属性设置为“True”。