How to use RequiredFieldValidator on ListBox in ASP.NET

September 16, 2013 0 Comments

If you want to apply RequiredField Validator to ListBox control then you should drop Required FieldValidator on design window. In previous example how to use RequiredFieldValidator control.

<%@ Page Language="C#" %>

<!DOCTYPE html>

<script runat="server">

    protected void Button1_Click(object sender, EventArgs e)
        Label1.Text = "you are selected <br/>" + ListBox1.SelectedItem.Text;

<html xmlns="">
<head runat="server">
    <form id="form1" runat="server">
        <asp:ListBox ID="ListBox1" runat="server" Height="136px" Width="110px">
            <asp:ListItem>Apple </asp:ListItem>
        <br />
        <asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ControlToValidate="ListBox1" ForeColor="#FF3300">Select any one in given list</asp:RequiredFieldValidator>
        <br />
        <asp:Label ID="Label1" runat="server"></asp:Label>
        <br />
        <asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="Submit" />

How to use RequiredFieldValidator on ListBox in ASP.NET

Jacob Lefore

Some say he’s half man half fish, others say he’s more of a seventy/thirty split. Either way he’s a fishy bastard. Google