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

Access Command Item Template via Javascript

3 Answers 184 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Kent Williams
Top achievements
Rank 1
Kent Williams asked on 13 Aug 2009, 03:14 PM
Hi,

I have a custom command item template similar to the top grid shown in http://demos.telerik.com/aspnet-ajax/grid/examples/programming/commanditem/defaultcs.aspx. What I am trying to do is, on the grid's 

RowSelected() event update some of my controls (set enabled, or visibility) to accuratly show what the user is allowed to do with that particular row. For example - they may or may not be able to delete, or edit on a per-row basis. I am having trouble obtaining references to the controls in the template. If any javascript tries to reference a control inside the template, the entire grid dosn't render. I suspect this is due to the naming containers, the compiler can't find a reference to anything when declared such as (sample):

    function RowSelected(sender, eventArgs)  
    {         
        //Enable the update tab  
        var tabStrip= $find("<%= RadTabStrip1.ClientID %>");  
        var tab = tabStrip.findTabByText("Update");  
        tab.set_enabled(true);  
    } 

Because this template is not a typical row template, the other examples I have found regarding accessing controls inside templates do not seem to apply. How would one be able to get a reference to the client ids to use in javascript?

 

Thanks,

 

Kent

 

3 Answers, 1 is accepted

Sort by
0
Daniel
Telerik team
answered on 14 Aug 2009, 02:18 PM
Hello Kent,

Try the following approach:
var radGrid = $get('<%= RadGrid1.ClientID %>'); 
$telerik.findControl(radGrid, "the_id_of_your_Telerik_control"

For HTML elements you should use $telerik.findElement instead.

Regards,
Daniel
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.
0
Simon
Top achievements
Rank 2
answered on 29 Oct 2013, 03:56 PM
Support -

I have tried to utilize your coded above but get an error with getElementsByTagName in your javascript (after fixing your syntax error).
Here is my code...

                    var button = $telerik.findControl(sender,"button_AddSelected");

...where button_AddSelected is a Command Item in a grid.

All I want to do is be able to post by firing this button-click event when someone clicks a specific column in a grid.

Thank you for any information you may have.

Simon.
0
Daniel
Telerik team
answered on 01 Nov 2013, 10:17 AM
Hello Simon,

If is a regular button you should use findElement instead of findControl.
Let me know if you need more information.

Regards,
Daniel
Telerik
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 the blog feed now.
Tags
Grid
Asked by
Kent Williams
Top achievements
Rank 1
Answers by
Daniel
Telerik team
Simon
Top achievements
Rank 2
Share this question
or