How to get access to all controls inside FormTempate of RadGrid.

4 posts, 0 answers
  1. JD.
    JD. avatar
    37 posts
    Member since:
    Aug 2012

    Posted 06 Oct 2011 Link to this post

    SOS -----  SOS.

    I have a RadGrid with FormTemplate having approx 30 controls including ASP.NET validation controls.
    I have a ClientSide CustomValidator which needs to access other control on the form using Javascript/JQuery to read its value  and also enable or disable some of Other validation controls.

    I tried to write following line on a clientside in a CustomValidation Control

    ValidatorEnable($(

     

    'RequiredFieldValidator4'), value);

     

    But that does not work and returns error "Microsoft JScript runtime error: 'null' is null or not an object"
    I also want to access other controls like textbox, RadmaskedTextbox etc inside CustomValidator control.

    Please tell me how to I get a successfull access to these controls.

    Regards
    JD


    <EditFormSettings EditFormType="Template" PopUpSettings-Width="900px" 
    CaptionFormatString="Edit Property: {0}"
    CaptionDataField="PropertyName"
    InsertCaption="Add New Property"
    PopUpSettings-Modal="true"
    PopUpSettings-Height="500px"
    PopUpSettings-ScrollBars="Vertical">
        <FormTemplate >
      
          ASP:RadTextBox  ......
           
       ASP:RadCombobox
      
      ASP:RequiredFieldValidator
      
     ASP:CustomValidator
      
       etc..... (approx 30 other controls)
        </FormTemplate >
  2. Veli
    Admin
    Veli avatar
    2002 posts

    Posted 07 Oct 2011 Link to this post

    Hello J.,

    You can use the $telerik.findControl() and $telerik.findElement() functions as follows:

    var grid = $find("RadGrid1").get_element();
    var radTextBox = $telerik.findControl(grid, "RadTextBox1");
    var combo = $telerik.findControl(grid, "RadComboBox1");
     
    var requiredVal = $telerik.findElement(grid, "RequiredFieldValidator4");
    ValidatorEnable(requiredVal, true);
     
    var customVal = $telerik.findElement(grid, "CustomValidator1");
    ValidatorValidate(customVal);

    $telerik.findControl() is used to find the client component of a Telerik control by specified server ID.
    $telerik.findElement() is used to find the container HTML element of a server control by specified server ID.

    These functions come in handy when you know the server ID of a control and its container, but do not know its client ID.

    For more info on what $telerik is all about, please refer to the Telerik Static Client Library HTML topic.

    Veli
    the Telerik team
    If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. JD.
    JD. avatar
    37 posts
    Member since:
    Aug 2012

    Posted 07 Oct 2011 Link to this post

    Hi

    Please see attached image.  I tried your statements, but its giving error .

    In Site.Master Page I have added following lines as per instruction mentioned on Link Here.

    <telerik:RadScriptManager ID="RadScriptMgr1" runat="server" >
       <Scripts>
                        <asp:ScriptReference Assembly="Telerik.Web.UI" Name="Telerik.Web.UI.Common.Core.js" />
                </Scripts>
    </telerik:RadScriptManager>



    Regards
    -JD

  5. Veli
    Admin
    Veli avatar
    2002 posts

    Posted 07 Oct 2011 Link to this post

    Hello J.,

    Obviously, RadGrid1 is not the client ID of your RadGrid. If you cannot retrieve the client ID of your grid. Try using the OnGridCreated client event of the control:

    <ClientEvents OnGridCreated="gridCreated" />

    function gridCreated(sender, args) { window.gridControl = sender; }

    And now you can use window.gridControl wherever needed:

    var grid = window.gridControl.get_element();
    var radTextBox = $telerik.findControl(grid, "RadTextBox1");
    var combo = $telerik.findControl(grid, "RadComboBox1");
      
    var requiredVal = $telerik.findElement(grid, "RequiredFieldValidator4");
    ValidatorEnable(requiredVal, true);
      
    var customVal = $telerik.findElement(grid, "CustomValidator1");
    ValidatorValidate(customVal);

    If this approach does not work for you, you can always use:

    $telerik.findElement(document.body, "CustomValidator1")

    but in this scenario, you need to make sure no other control on your page ends with the string you specified as an ID.

    Veli
    the Telerik team
    If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now
Back to Top