New to Telerik UI for ASP.NET AJAX? Download free 30-day trial

Validation

  • Apartments
  • Campings
  • Hotels
  • Hostels
  • Rooms
  • Villas
 
  • Burundi
  • Comoros
  • Djibouti
  • Eritrea
  • Ethiopia
 

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" />
  • DefaultVB.aspx
  • DefaultVB.aspx.vb
  • styles.css
<%@ Page Language="VB" AutoEventWireup="false" CodeFile="DefaultVB.aspx.vb" Inherits="ListBox.Examples.Functionality.Validation.DefaultVB" %>

<%@ Register TagPrefix="telerik" Namespace="Telerik.Web.UI" Assembly="Telerik.Web.UI" %>
<!DOCTYPE html>
<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>

Support & Learning Resources

Find Assistance