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

Find a grid in a JS file

1 Answer 93 Views
Grid
This is a migrated thread and some comments may be shown as answers.
dhuss
Top achievements
Rank 1
dhuss asked on 15 Dec 2010, 11:04 PM
The following code works fine as javascript that is behind the aspx page, however if it is called from a standalone JS file it bombs out. What is the correct code to locate a datagrid on a page.


var masterTable = $find("<%=dgServices.ClientID %>").get_masterTableView();

1 Answer, 1 is accepted

Sort by
0
Accepted
Princy
Top achievements
Rank 2
answered on 16 Dec 2010, 10:56 AM
Hello Dhuss,

Javascript external files are not run through the ASP.NET engine, so the server tag <%=...%> is never executed in that case. In order to access any control ClientID, use a global variable in the aspx file itself, and save the ClientID when page loads.  Now you will be able to access the control (from external JS file) uisng the ClientID saved in global variable.

In the aspx page: save the ClientID

aspx:
<script type="text/javascript">
    var gridID = '<%= RadGridJobs2.ClientID %>'; 
</script>

JavaScript:
function getGrid()
 {
    var masterTable = $find(gridID).get_masterTableView();
 }

Thanks,
Princy.
Tags
Grid
Asked by
dhuss
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Share this question
or