I have a drop down list with required field validator that is not showing up when the user clicks on the button. The user has to select an item from the drop down list, if he leaves it at --Select One-- the required field validator will fire. I noticed that on firebug it shows visibility as hidden.
<span id="MainContent_RequiredFieldValidator1" style="color: red; visibility: hidden;">*</span>
This works for my other dropdownlists that are not Databound. It shows visibility:visible for this dropdownlists.
<asp:DropDownList ID="ddlCenter" runat="server" AppendDataBoundItems="True"
CssClass="form-control textBoxAsp" DataSourceID="SqlDataSourceCenter"
DataTextField="Desc" DataValueField="CenterID">
<asp:ListItem Text="--Select One--" Value="0" Selected="True" />
</asp:DropDownList>
<asp:RequiredFieldValidator runat="server" ID="RequiredFieldValidator1"
ControlToValidate="ddlCenter"
Text="*"
ForeColor="Red"
ErrorMessage="Center is required."
InitialValue ="--Select One--"
ValidationGroup="InsertCenter" />
<asp:ValidationSummary ID="ValidationSummary1" ForeColor="Red" runat="server" ValidationGroup="InsertCenter" />
<a runat="server" onserverclick="btnAddCenter_Click" id="btnAddUser" validationgroup="InsertEmployee">Add Center</a>
I tried setting Display="Static"
,but the Validator control's style property is actually set as "visibility:hidden
".
I tried setting set Display="Dynamic"
, but the Validator controls style property is actually set as "display:none
"
Any ideas?
The Initial Value
refers to the Value
property of the DropDownList
rather than the Text
value; hence try setting the Initial Value
of the RequiredFieldValidator
to 0.