Validate dropdownlist in asp.net using c#
In this tutorial, we are going to discuss "How to validate dropdownlist in asp.net". 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 asp.net
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:DropDownList>
<asp:RequiredFieldValidator ID="req121" runat="server" ErrorMessage="*" ControlToValidate="ddlLectureTime" ValidationGroup="Save" InitialValue="0" Font-Bold="true" ForeColor="Red"></asp:RequiredFieldValidator>
</td>
<td>
<asp:Button ID="btnSave" runat="server" Text="Save" ValidationGroup="Save" OnClick="btnSave_Click" OnClientClick="parent.scrollTo(0, 0); return true" CssClass="btnSave" />
</td>
Post a Comment