0

I have a RequiredFieldValidator for dropdownlist. Both are inside UpdatePanel. It is not validating user selection from dropdownlist when submit button is clicked. Please guide what am I missing.

   <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>
SilverFish
  • 1,014
  • 6
  • 28
  • 65

1 Answers1

0

Try setting the Enabled attribute in the RequiredFieldValidator element to "True".

Gilligan
  • 451
  • 1
  • 5
  • 14
  • 1
    Actually, try setting the **InitialValue** attribute in the RequiredFieldValidator to "-1". This tells the validator to fail validation if the value submitted is "-1", which is your default value for drop-down list. https://msdn.microsoft.com/en-us/library/5hbw267h(vs.80).aspx – Gilligan Apr 11 '17 at 01:31
  • @Giligan- this worked thanks. But in actual application there is some JavaScript code to visible/invisible divs, so it is not working as expected. I will create a new post with that code – SilverFish Apr 11 '17 at 02:22