You can verify at client side that any value in dropdownlist is selected or not. Here is a simple example which have dropdown with some values and first value is “Select”. Comparevalidator checkes for non Select value in dropdown otherwise it stops the execution and promp a error message to select a value from dropdownlist. Inplace of Select if you have a blank value at first place in dropdown then youcan change the value of
ValueToCompare="Select"
To
ValueToCompare=""
How to Check/Compaire/Validate DropDownList selection at client side in ASP.NET | CompareValidator Example:
<%@ Page Language="C#" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" >
<html>
<body>
<form id="Form1" runat="server">
<h4>
Compare Two Password Values</h4>
<br />
<br />
Select a Dropdown Value:
<asp:DropDownList ID="DropDownList1" runat="server">
<asp:ListItem>Select</asp:ListItem>
<asp:ListItem>IndiHub.com</asp:ListItem>
<asp:ListItem>SoftwareTestingNet.com</asp:ListItem>
</asp:DropDownList>
<br />
<br />
<asp:Button ID="Button1" Text="Validate" runat="server" />
<br />
<br />
<asp:CompareValidator ID="compair_dropdown_blank_value" ControlToValidate="DropDownList1" ValueToCompare="Select"
ForeColor="red" Type="string" Text="Please Select at least one value to proceed."
Operator="notequal" runat="server" />
</form>
</body>
</html>
0 comments:
Post a Comment