How to add target controls to RadInputManager programatically?

4 posts, 1 answers
  1. jgill
    jgill avatar
    116 posts
    Member since:
    Jul 2005

    Posted 20 Dec 2008 Link to this post

    I wanted to know if there is a way I can add validation elements/settings to the RadInputManager dynamically for a situation where all validation criteria is stored in a database. 

    For example: Imagine you have a form that is dynamically generated from database data and the number of input fields to validate and their names are not fixed/known ahead of time.  Fields are dynamically loaded from the database and they are named vaules like txtControl12.

            'Create an instance of the RadInputManager  
            Dim controlvalidation As New RadInputManager  
            controlvalidation.ID = "RadInputManager1" 
            'Add various settings and specific controls to validate within those settings  
            'E.g. There is one field in the form that should be an e-mail address, 1 field that  
            'has a validation date range, another field that has a different validation date  

    In the example above there are 2 different date validations for two date input fields and 1 e-mail address.  I am looking for a way to programatically create the VB.NET/C# equal to the following, but am having trouble figuring out how to add something like a new DateInputSetting for RadInputManager 1 that applies to control X and a RegExpTextBoxSetting that applies to a different set of controls (it could apply to one or more).
    <telerik:RadInputManager ID="RadInputManager1" runat="server">     
            <telerik:DateInputSetting MinDate="1/1/1980" MaxDate="1/1/2020">     
                <ClientEvents OnError="onClientDateTxtError" OnKeyPress="onClientTextChanged" />    
                    <telerik:TargetInput ControlID="txtControl1" />    
            <telerik:DateInputSetting MinDate="1/1/2009" MaxDate="1/1/2030">     
                <ClientEvents OnError="onClientDateTxtError" OnKeyPress="onClientTextChanged" />    
                    <telerik:TargetInput ControlID="txtControl2" />    
            <telerik:RegExpTextBoxSetting IsRequiredFields="true" ValidationExpression="^\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$">     
                <ClientEvents OnError="onClientRegTxtError" OnKeyPress="onClientTextChanged" />    
                    <telerik:TargetInput ControlID="txtControl3" />    

    Any help would be appreciated.  Thank you.
  2. Answer
    Dimo avatar
    8318 posts

    Posted 21 Dec 2008 Link to this post

    Hi Jonathan,

    Adding a RadInputManager programmatically is pretty straightforward. Here is an example:

    <%@ Page Language="VB" %> 
    <%@ Register Assembly="Telerik.Web.UI" Namespace="Telerik.Web.UI" TagPrefix="telerik" %> 
    <script runat="server"
        Protected Sub Page_Init(ByVal sender As Object, ByVal e As EventArgs) 
            Dim InputMgr As RadInputManager = New RadInputManager 
            InputMgr.ID = "RadInputManager1" 
            InputMgr.Skin = "Vista" 
            Dim DateSetting As DateInputSetting = New DateInputSetting 
            DateSetting.MinDate = New DateTime(1980, 1, 1) 
            DateSetting.MaxDate = New DateTime(2020, 1, 1) 
            DateSetting.ClientEvents.OnError = "onClientDateTxtError" 
            DateSetting.ClientEvents.OnKeyPress = "onClientTextChanged" 
            TryCast(InputMgr.InputSettings(0), InputSetting).TargetControls.Add(New TargetInput(TextBox1.UniqueID, True)) 
        End Sub 
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
    <html xmlns=""
    <head runat="server"
    <meta http-equiv="content-type" content="text/html; charset=utf-8" /> 
    <title>RadControls for ASP.NET AJAX</title> 
    <form id="form1" runat="server"
    <asp:ScriptManager ID="ScriptManager1" runat="server" /> 
    <asp:TextBox ID="TextBox1" runat="server" /> 
    <script type="text/javascript"
    function onClientDateTxtError(sender, args) 
        // do something 
    function onClientTextChanged(sender, args) 
        // do something 

    Best wishes,
    the Telerik team

    Check out Telerik Trainer, the state of the art learning tool for Telerik products.
  3. DevCraft R3 2016 release webinar banner
  4. towpse
    towpse avatar
    224 posts
    Member since:
    Mar 2008

    Posted 29 May 2009 Link to this post

    I tried a couple of ways but my input settings are always null on the client side.

        <script runat="server">  
                void Page_Init(object sender, EventArgs e){ 
                    RadInputManager input = new RadInputManager(); 
                    input.ID = "RadInputManager1"
                    NumericTextBoxSetting numSet = new NumericTextBoxSetting(); 
                    numSet.BehaviorID = "NumericSettings"
                    input.InputSettings[0].TargetControls.Add(new TargetInput(TextBox1.UniqueID, true)); 

         <%-- The following TextBox is required by the InputManager --%>  
        <asp:TextBox ID="TextBox1" runat="server" Visible="false" />  
        <telerik:RadInputManager ID="RadInputManager" runat="server" Skin="Vista"
            <telerik:NumericTextBoxSetting BehaviorID="NumericSettings" InitializeOnClient="true" Type="Number" DecimalDigits="1" GroupSizes="3" GroupSeparator="," PositivePattern="n" NegativePattern="-n">  
                    <telerik:TargetInput ControlID="TextBox1" /> 
            <telerik:TextBoxSetting BehaviorID="TextSettings" InitializeOnClient="true"  > 
                    <telerik:TargetInput ControlID="TextBox1" /> 

    When I try to access the numeric settings to add more controls to it in my javascript, the input setting is always null. What might I be missing?

    Ideally I'd like to be able to do this:
                    var numericSettings = $find('RadInputManager').get_inputSettings('NumericSettings'); 
                    Array.forEach(elements, function(element) { 

  5. Dimo
    Dimo avatar
    8318 posts

    Posted 30 May 2009 Link to this post

    Here is a page that demonstrates how to add targer inputs programmatically on the client:

    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Check out the tips for optimizing your support resource searches.
Back to Top