Telerik is a leading vendor of ASP.NET AJAX, ASP.NET MVC, Silverlight, WinForms and WPF controls and components, as well as .NET Reporting, .NET ORM , .NET CMS, Code Analysis, Mocking, Team Productivity and Automated Testing Tools. Building on its expertise in interface development and Microsoft technologies, Telerik helps customers build applications with unparalleled richness, responsiveness and interactivity. Telerik products help thousands of companies to be more productive and deliver reliable applications under budget and on time.
Version Q2 2011 released 07/12/2011
select

Editor / Validator Support

Registration Form
First Name: *
Last Name: *
Skill Level:
Address: *
Resume: *
   
  
 
 
   


   

  • Using RadEditor with ASP.NET Validators

    RadEditor will usually be used as a replacement for the regular TextBox control which offers support for validators such as <asp:RequiredFieldValidator> and <asp:CustomValidator>. The example demonstrates how to attach <asp:RequiredFieldValidator> and <asp:CustomValidator> controls to RadEditor:

    <telerik:radeditor runat="server" ID="RadEditor1"></telerik:radeditor>

    <
    asp:RequiredFieldValidator ID="ResumeValidator" Runat="server"
        ControlToValidate
    ="RadEditor1"
        Display
    ="Static">Please fill in your RESUME!!!
    </asp:RequiredFieldValidator>

    <
    asp:CustomValidator runat="server" ID="CustomValidator1" ControlToValidate="RadEditor1" ClientValidationFunction="checkLength">* The text length should not exceed 50 symbols.</asp:CustomValidator>  
    <script type="text/javascript">  
       
    var limitNum = 50;  
           
        function
    checkLength(sender, args)  
        {  
           
    //Note that sender is NOT the RadEditor. sender is the <span> of the validator. 
            //The content is contained in the args.Value variable     
           
    var editorText = args.Value
           
    args.IsValid = editorText.length > limitNum;  
       
    }  
    </script>

     

Source Code

C# VB.NET
Show code in new window Demo isolation steps
  • <%@ Page Theme="Default" Language="C#" Debug="true" AutoEventWireup="true" CodeFile="DefaultCS.aspx.cs" Inherits="Telerik.Web.Examples.Editor.Validators.DefaultCS" %>
    <%@ Register TagPrefix="telerik" Namespace="Telerik.Web.UI" Assembly="Telerik.Web.UI" %>
    <%@ Register TagPrefix="qsf" Namespace="Telerik.QuickStart" %>
    <%@ Register TagPrefix="qsf" TagName="Header" Src="~/Common/Header.ascx" %>
    <%@ Register TagPrefix="qsf" TagName="HeadTag" Src="~/Common/HeadTag.ascx" %>
    <%@ Register TagPrefix="qsf" TagName="Footer" Src="~/Common/Footer.ascx" %>
    <!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">
        <qsf:headtag id="Headtag1" runat="server"/>
    </head>
    <body class="BODY">
        <form id="form1" runat="server">
                             
            <qsf:header id="Header1" runat="server" navigationlanguage="c#"/>
         <telerik:RadScriptManager ID="ScriptManager1" runat="server" />    
                <table>
                        <tr>
                            <td colspan="3"><b>Registration Form</b></td>
                        </tr>
                        <tr>
                            <td style="white-space:nowrap;">First Name:</td>
                            <td><asp:TextBox id="FirstBox" runat="server"></asp:TextBox> *</td>
                            <td style="width:300px;">
    <asp:RequiredFieldValidator ID="FirstValidator" Runat="server"
    ControlToValidate="FirstBox"
    Display="Dynamic">Please fill in first name!</asp:RequiredFieldValidator>

                            </td>
                        </tr>
                        <tr>
                            <td style="white-space:nowrap;">Last Name:</td>
                            <td><asp:TextBox id="LastBox" runat="server"></asp:TextBox> *</td>
                            <td>
    <asp:RequiredFieldValidator ID="LastValidator" Runat="server"
    ControlToValidate="LastBox"
    Display="Dynamic">Please fill in last name!</asp:RequiredFieldValidator>

                            </td>
                        </tr>
                        <tr>
                            <td style="white-space:nowrap;">Skill Level:</td>
                            <td>
                                <asp:dropdownlist id="ExperienceList" runat="server">
                                    <asp:ListItem Value="No Experience" Selected="True">No Experience</asp:ListItem>
                                    <asp:ListItem Value="Beginner">Beginner</asp:ListItem>
                                    <asp:ListItem Value="Good">Good</asp:ListItem>
                                    <asp:ListItem Value="Excellent">Excellent</asp:ListItem>
                                </asp:dropdownlist>
                            </td>
                            <td></td>
                        </tr>
                        <tr>
                            <td style="white-space:nowrap;">Address:</td>
                            <td style="white-space:nowrap;"><asp:TextBox id="AddressBox" Width="254px" runat="server" TextMode="MultiLine" Columns="40" Rows="3"></asp:TextBox> *</td>
                            <td>
    <asp:RequiredFieldValidator ID="AddressValidator" Runat="server"
    ControlToValidate="AddressBox"
    Display="Dynamic">Please fill in your address!</asp:RequiredFieldValidator>

                            </td>
                        </tr>
                        <tr>
                            <td style="white-space:nowrap;">Resume: *</td>
                            <td colspan="2">
                            <telerik:radeditor runat="server" SkinID="BasicSetOfTools" ID="RadEditor1">
                            </telerik:radeditor>
                            <br/>
    <asp:RequiredFieldValidator ID="ResumeValidator" Runat="server"
    ControlToValidate="RadEditor1"
    Display="Static">Please fill in your RESUME!!!

                            </asp:RequiredFieldValidator><br />
    <asp:CustomValidator runat="server" ID="CustomValidator1"
    ControlToValidate="RadEditor1"
    Display="static"
    ClientValidationFunction="checkLength">* Your resume is too short. Its length should be at least 50 symbols.</asp:CustomValidator>

                            <script type="text/javascript">
                                var limitNum = 50;
                                   
                                function checkLength(sender, args)
                                {
                                    //Note that sender is NOT the RadEditor. sender is the span of the validator.
                                    //The content is contained in the args.Value variable
                                    var editorText = args.Value;
                                    args.IsValid = editorText.length > limitNum;
                                }
                            </script>
                            
                            </td>
                        </tr>
                        <tr>
                            <td colspan="3">
                                <table cellpadding="1" cellspacing="0" width="100%">
                                    <tr>
                                        <td align="center">
                                            <asp:button Runat="server" ID="Submit" Text="Submit" Width="80px" CssClass="button"></asp:button>&nbsp;&nbsp;&nbsp;
                                        </td>
                                    </tr>
                                </table>
                            </td>
                        </tr>
                    </table>
            <qsf:Footer runat="server" ID="Footer1" />
                
        </form>
    </body>
    </html>

Get more than expected!

 
 

Take your time to truly experience the power of RadControls for ASP.NET AJAX with a free 60-day trial backed up by Telerik’s unlimited dedicated support.

Download your RadControls for ASP.NET AJAX trial and jumpstart your development with the available Getting Started resources.

If you have any questions, do not hesitate to contact us at sales@telerik.com.

Copyright 2002-2024 © Telerik. All right reserved
Telerik Inc, 201 Jones Rd, Waltham, MA 02451