---
title: "asp.net listbox validation pass without a value selected"  
description: "asp.net listbox validation pass without a value selected"  
author: "Manoj Bhatt"  
published: 2013-12-18  
updated: 2013-12-18  
canonical: https://www.mindstick.com/forum/1805/asp-dot-net-listbox-validation-pass-without-a-value-selected  
category: "c#"  
tags: ["c#"]  
reading_time: 1 minute  

---

# asp.net listbox validation pass without a value selected

I have a [listbox](https://www.mindstick.com/articles/626/listbox-events-in-c-dot-net) with [Data](https://www.mindstick.com/articles/13050/salesforce-aiming-to-dominate-predictive-analytics-with-data-science) coming from a database. But the [validation](https://www.mindstick.com/articles/12234/validation-using-data-annotation-using-entity-framework) passes even when [value](https://www.mindstick.com/articles/23219/an-optimized-description-adds-value-to-experience-and-in-turn-effectively-guest-posting-packages) is not selected. I have tried ,just [simple](https://yourviews.mindstick.com/story/1469/5-simple-ways-to-stay-fit-amp-healthy) [required](https://www.mindstick.com/forum/160269/what-is-required-data-annotation-how-does-it-affect-model-validation) [field](https://www.mindstick.com/forum/160867/does-mindstick-provide-training-for-field-marketing) [validator](https://www.mindstick.com/forum/156905/what-is-data-annotation-validator-attribute-in-asp-dot-net-mvc) 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>
```

## Replies

### Reply by Anonymous User

Hi Manoj,

By 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

```
<asp:ListBox ID="ListBox1" runat="server">                                                                                                                                   
<asp:ListItem Text="1" Value="1" ></asp:ListItem>                           
<asp:ListItem Text="2" Value="2" ></asp:ListItem>                           
<asp:ListItem Text="2" Value="2" ></asp:ListItem>   
</asp:ListBox>   
<asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server"   
ErrorMessage="Error, Select value" ControlToValidate="ListBox1"></asp:RequiredFieldValidator><asp:ListBox ID="ListBox1" runat="server">                       
<asp:ListItem Text="1" Value="1" Selected="True"></asp:ListItem>                       
<asp:ListItem Text="2" Value="2" ></asp:ListItem>                       
<asp:ListItem Text="2" Value="2" ></asp:ListItem></asp:ListBox><asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server"
ErrorMessage="RequiredFieldValidator" ControlToValidate="ListBox1" InitialValue="1"></asp:RequiredFieldValidator>
```


---

Original Source: https://www.mindstick.com/forum/1805/asp-dot-net-listbox-validation-pass-without-a-value-selected

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
