This is a migrated thread and some comments may be shown as answers.

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

5 Answers 454 Views
Grid
This is a migrated thread and some comments may be shown as answers.
JD.
Top achievements
Rank 1
JD. asked on 06 Oct 2011, 09:07 PM
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 >

5 Answers, 1 is accepted

Sort by
0
Veli
Telerik team
answered on 07 Oct 2011, 07:46 AM
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
0
JD.
Top achievements
Rank 1
answered on 07 Oct 2011, 12:52 PM
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

0
Veli
Telerik team
answered on 07 Oct 2011, 02:55 PM
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
0
MV
Top achievements
Rank 1
answered on 18 Jan 2017, 09:30 PM

Hi,

I have a RadGrid with EditForm Template. I am able to find the Insert/Update button when in edit mode, but not in Insert mode. How can I accomplish this?

Thanks

<ClientSettings EnablePostBackOnRowClick="false" ClientEvents-OnKeyPress="Submit" >
</ClientSettings>
 
function Submit(sender, eventArgs) {
 
                if (event.keyCode == 13) {
 
                    //eventArgs.set_cancel(true);
 
                    eventArgs._domEvent.preventDefault();
 
                    var editForm = $find("<%=RadGrid1.ClientID%>").get_masterTableView().get_editItems()[0].get_editFormItem();
 
                    $telerik.findElement(editForm, "btnUpdate").click();
 
     }
            }
0
MV
Top achievements
Rank 1
answered on 19 Jan 2017, 06:02 PM

I figured it out, here it is in case somebody else needs it.

var editForm1 = $find("<%=RadGrid1.ClientID%>").get_masterTableView().get_insertItem();                      
$telerik.findElement(editForm1, "btnUpdate").click();
Tags
Grid
Asked by
JD.
Top achievements
Rank 1
Answers by
Veli
Telerik team
JD.
Top achievements
Rank 1
MV
Top achievements
Rank 1
Share this question
or