Home > ASP.Net > Validating a ListBox Using Required Field Validator in Asp.Net

Validating a ListBox Using Required Field Validator in Asp.Net


Hi all,

Try this example to Validate a ListBox Using Required Field Validator in Asp.Net

<asp:Content ID="BodyContent" runat="server" ContentPlaceHolderID="MainContent">
<asp:ListBox ID = "ListBox1" runat = "server" Width="200" Height="200" SelectionMode = "Multiple">
<asp:ListItem Value="1">January</asp:ListItem>
<asp:ListItem Value="2">February</asp:ListItem>
<asp:ListItem Value="3">March</asp:ListItem>
<asp:ListItem Value="4">April</asp:ListItem>
<asp:ListItem Value="5">May</asp:ListItem>
<asp:ListItem Value="6">June</asp:ListItem>
<asp:ListItem Value="7">July</asp:ListItem>
<asp:ListItem Value="8">August</asp:ListItem>
<asp:ListItem Value="9">September</asp:ListItem>
<asp:ListItem Value="10">October</asp:ListItem>
<asp:ListItem Value="11">November</asp:ListItem>
<asp:ListItem Value="12">December</asp:ListItem>
</asp:ListBox>
<asp:RequiredFieldValidator ID = "RequiredFieldValidator1" ControlToValidate ="ListBox1" InitialValue = "" runat="server" ErrorMessage = "*" ForeColor="Red"></asp:RequiredFieldValidator>


<hr />
<asp:Button ID="Button1" runat="server" Text="Save" />
</asp:Content>

Hope this helps

Good Luck.

Advertisements
Categories: ASP.Net
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: