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

Find grid with javascript, might return null

2 Answers 104 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Wired_Nerve
Top achievements
Rank 2
Wired_Nerve asked on 21 Oct 2010, 11:28 PM
Finally figured out how to get the code on the master page to deal with this... Would delete this post, but I do not see an option...










I have master page and on this page I have a javascript section that I need to have search the current page to see if a radgrid is on that page.

I tried 
   var control = document.getElementById('<%= RadGridStudents.ClientID %>');
                if (control == null) {
but it returns an error because the grid is not there - of course.



What is the best way in javascript to see if the current page has an element on it before continuing...

2 Answers, 1 is accepted

Sort by
0
Wired_Nerve
Top achievements
Rank 2
answered on 22 Oct 2010, 05:39 PM
   var div, i;
                // Loop through all divs, check if they contain the RadGridStudents
                divs = document.getElementsByTagName('div');
                for (i = 0; i < divs.length; i++) {
                    var rg = divs[i].id;
                    var result = rg.search('RadGridStudents');
                    if (result != -1) {
                        alert(result);
                    }
                    
                }
0
Mira
Telerik team
answered on 26 Oct 2010, 02:11 PM
Hello Warren,

Please take a look at the Getting RadGrid client object help topic to see how the desired functionality can be implemented.

I hope this helps.

Best wishes,
Mira
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
Tags
Grid
Asked by
Wired_Nerve
Top achievements
Rank 2
Answers by
Wired_Nerve
Top achievements
Rank 2
Mira
Telerik team
Share this question
or