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  
            'range.  
     

    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" />    
                <TargetControls>    
                    <telerik:TargetInput ControlID="txtControl1" />    
                </TargetControls>    
            </telerik:DateInputSetting>   
            <telerik:DateInputSetting MinDate="1/1/2009" MaxDate="1/1/2030">     
                <ClientEvents OnError="onClientDateTxtError" OnKeyPress="onClientTextChanged" />    
                <TargetControls>    
                    <telerik:TargetInput ControlID="txtControl2" />    
                </TargetControls>    
            </telerik:DateInputSetting>   
       
            <telerik:RegExpTextBoxSetting IsRequiredFields="true" ValidationExpression="^\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$">     
                <ClientEvents OnError="onClientRegTxtError" OnKeyPress="onClientTextChanged" />    
                <TargetControls>    
                    <telerik:TargetInput ControlID="txtControl3" />    
                </TargetControls>    
            </telerik:RegExpTextBoxSetting>    
        </telerik:RadInputManager>    
     


    Any help would be appreciated.  Thank you.
  2. Answer
    Dimo
    Admin
    Dimo avatar
    8353 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" 
            InputMgr.InputSettings.Add(DateSetting) 
             
            TryCast(InputMgr.InputSettings(0), InputSetting).TargetControls.Add(New TargetInput(TextBox1.UniqueID, True)) 
             
            Me.Page.Form.Controls.Add(InputMgr) 
             
        End Sub 
         
    </script> 
     
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
     
    <html xmlns="http://www.w3.org/1999/xhtml"
    <head runat="server"
    <meta http-equiv="content-type" content="text/html; charset=utf-8" /> 
    <title>RadControls for ASP.NET AJAX</title> 
    </head> 
    <body> 
    <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 
     
    </script> 
     
    </form> 
    </body> 
    </html> 
     


    Best wishes,
    Dimo
    the Telerik team

    Check out Telerik Trainer, the state of the art learning tool for Telerik products.
  3. 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.

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

    B
         <%-- 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">  
                <TargetControls> 
                    <telerik:TargetInput ControlID="TextBox1" /> 
                </TargetControls> 
            </telerik:NumericTextBoxSetting> 
            <telerik:TextBoxSetting BehaviorID="TextSettings" InitializeOnClient="true"  > 
                <TargetControls> 
                    <telerik:TargetInput ControlID="TextBox1" /> 
                </TargetControls> 
            </telerik:TextBoxSetting> 
        </telerik:RadInputManager> 

    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) { 
                        numericSettings.addTargetInput(element.id); 
                    });


    thanks
  4. Dimo
    Admin
    Dimo avatar
    8353 posts

    Posted 30 May 2009 Link to this post

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

    http://www.telerik.com/community/forums/aspnet-ajax/input/problems-getting-input-settings-on-the-client.aspx


    Dimo
    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