Required field validator for dropdown in C# - Solved

 Validator for dropdown in C#

In this tutorial, we are going to discuss about "required field validator for dropdown in". Here we take one drop-down control and one button to check wheater our validation works or not.

Step to implement validation for Dropdown control
1. Add a required field validator.
2. Match the id of Dropdown control with requireFieldValidator's property controlToValidate
3. Give the error message.

<td align="left">
   <asp:DropDownList ID="ddlLectureTime" runat="server" AutoPostBack="True" CssClass="DropDown"     OnSelectedIndexChanged="ddlLectureTime_SelectedIndexChanged">

  <asp:RequiredFieldValidator ID="req121" runat="server" ErrorMessage="*" ControlToValidate="ddlLectureTime"     ValidationGroup="Save"   InitialValue="0" Font-Bold="true" ForeColor="Red"></asp:RequiredFieldValidator>

  <asp:Button ID="btnSave" runat="server" Text="Save"  ValidationGroup="Save" OnClick="btnSave_Click" OnClientClick="parent.scrollTo(0, 0); return true" CssClass="btnSave" />
Next Post »