I have a listbox with Data coming from a database. But the validation passes even when value is not selected. I have tried ,just simple required field validator and does not work either. Here is the code.
<asp:Panel ID="panelDelivery" runat="server" Visible="false"
style="position: relative; top: -130px; background-color: #66FF33; left: 0px;" >
<asp:Label ID="lblOverWeight" runat="server" Width="344px"></asp:Label><br />
<asp:ListBox ID="listBxDelivery" runat="server" DataSourceID="Delivery"
DataTextField="DataText" DataValueField="Price" Width="489px"
AppendDataBoundItems="True" CausesValidation="True" AutoPostBack="True"
style="top: 0px; left: 0px">
</asp:ListBox>
<asp:RequiredFieldValidator ID="rfvDelivery" runat="server"
ErrorMessage="* Select Delivery " ControlToValidate="listBxDelivery"></asp:RequiredFieldValidator>
Anonymous User
18-Dec-2013By default requiredFieldValidator will compare its initialValue(default is "") and ControlToValidate selected value. make sure you not set the listbox selectedvalue, if you change it also change the initial value of the requiredFieldValidator. See examples below