ListBox - Validation

  • Apartments
  • Campings
  • Hotels
  • Hostels
  • Rooms
  • Villas
 
  • Burundi
  • Comoros
  • Djibouti
  • Eritrea
  • Ethiopia
 
Isolate this demo as a stand-alone application
  • About this demo
  • C#
  • VB

This example demonstrates how to validate the selection of RadListBox. Each listbox is validated using RequiredFieldValidator control. If the user does not select an item the validators will fail and show their error message.

Click the "Search Offers" button to trigger validation.

ASPX

<telerik:RadListBox runat="server" ID="RadListBox1">
	<Items>
		<telerik:RadListBoxItem Text="Apartments" />
		<telerik:RadListBoxItem Text="Campings" />
		<telerik:RadListBoxItem Text="Hotels" />
		<telerik:RadListBoxItem Text="Hostels" />
		<telerik:RadListBoxItem Text="Rooms" />
		<telerik:RadListBoxItem Text="Villas" />
	</Items>
</telerik:RadListBox>
<asp:RequiredFieldValidator runat="server" ID="RequiredFieldValidator1" 
ErrorMessage="Please, select item!" ControlToValidate="RadListBox1" />
  • DefaultCS.aspx
  • DefaultCS.aspx.cs
  • styles.css
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="DefaultCS.aspx.cs" Inherits="ListBox.Examples.Functionality.Validation.DefaultCS" %>

<%@ Register TagPrefix="telerik" Namespace="Telerik.Web.UI" Assembly="Telerik.Web.UI" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns='http://www.w3.org/1999/xhtml'>
<head runat="server">
    <title>Telerik ASP.NET Example</title>
    <link href="styles.css" rel="stylesheet" type="text/css" />
</head>
<body>
    <form id="form1" runat="server">
    <telerik:RadScriptManager runat="server" ID="RadScriptManager1" />
    <telerik:RadSkinManager ID="RadSkinManager1" runat="server" ShowChooser="true" />
    <div class="demo-container">
        <label class="search-for">
            Search for:</label>
        <telerik:RadListBox RenderMode="Lightweight" runat="server" ID="RadListBox1" CssClass="RadListBox1" Width="180px" Height="140px"
            SelectionMode="Multiple">
            <Items>
                <telerik:RadListBoxItem Text="Apartments"></telerik:RadListBoxItem>
                <telerik:RadListBoxItem Text="Campings"></telerik:RadListBoxItem>
                <telerik:RadListBoxItem Text="Hotels"></telerik:RadListBoxItem>
                <telerik:RadListBoxItem Text="Hostels"></telerik:RadListBoxItem>
                <telerik:RadListBoxItem Text="Rooms"></telerik:RadListBoxItem>
                <telerik:RadListBoxItem Text="Villas"></telerik:RadListBoxItem>
            </Items>
        </telerik:RadListBox>
        <asp:RequiredFieldValidator runat="server" ID="RequiredFieldValidator1" CssClass="RequiredFieldValidator1" ErrorMessage="Please, select item!"
            ControlToValidate="RadListBox1"></asp:RequiredFieldValidator>
        <label class="search-in">
            Search in:</label>
        <telerik:RadListBox RenderMode="Lightweight" runat="server" ID="RadListBox2" CssClass="RadListBox2" Width="180px" Height="140px"
            SelectionMode="Multiple">
            <Items>
                <telerik:RadListBoxItem Text="Burundi"></telerik:RadListBoxItem>
                <telerik:RadListBoxItem Text="Comoros"></telerik:RadListBoxItem>
                <telerik:RadListBoxItem Text="Djibouti"></telerik:RadListBoxItem>
                <telerik:RadListBoxItem Text="Eritrea"></telerik:RadListBoxItem>
                <telerik:RadListBoxItem Text="Ethiopia"></telerik:RadListBoxItem>
            </Items>
        </telerik:RadListBox>
        <asp:RequiredFieldValidator runat="server" ID="RequiredFieldValidator2" CssClass="RequiredFieldValidator2" ErrorMessage="Please, select item!"
            ControlToValidate="RadListBox2"></asp:RequiredFieldValidator>
        <asp:ImageButton runat="server" ID="ImageButton1" CssClass="ImageButton1" ImageUrl="Images/button.png"></asp:ImageButton>
        <asp:ValidationSummary runat="server" ID="ValidationSummary1" CssClass="ValidationSummary1" HeaderText="Invalid search">
        </asp:ValidationSummary>
    </div>
    </form>
</body>
</html>

Find Assistance

Help Us Improve

Was this example helpful?