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

$find(...) results in a null object

1 Answer 52 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Developer Developer
Top achievements
Rank 1
Developer Developer asked on 18 Aug 2011, 07:18 PM
I had some code that was working until the latest release of 2011.2.712.40. From RadGrid's OnMasterTableViewCreated:
 

<ClientEvents OnMasterTableViewCreated="DoStuff" />


Looked like this:

 

function DoStuff(sender, args) {
  var tabStrip = $find("<%= MainTabStrip.ClientID %>");
  var pageViewID = tabStrip.get_multiPage().get_selectedPageView()._id;
  ...

BUT tabStrip.get_multiPage() was null!! If I did NOT call this code, it was NOT null a second later, but if I DID call it, it would be stuck as null. Seems like the JS objects weren't loading as [I] expected. Perhaps the order of events changed somwhere?

This is my fix, using setTimeout:
function DoStuff(sender, args) {
  setTimeout(function() {
    var tabStrip = $find("<%= MainTabStrip.ClientID %>"); 
    var pageViewID = tabStrip.get_multiPage().get_selectedPageView()._id;
  }, 0);
  ...
}

1 Answer, 1 is accepted

Sort by
0
Tsvetina
Telerik team
answered on 22 Aug 2011, 03:09 PM
Hello,

Even if it was working before, it is not a recommended approach to try to access one control in the control created event of another control, there is no guarantee that if the MasterTableView of the RadGrid is created that the RadTabStrip client object is created too. I would advise you to use the client pageLoad event to ensure that all controls are created when your logic runs.

Regards,
Tsvetina
the Telerik team

Thank you for being the most amazing .NET community! Your unfailing support is what helps us charge forward! We'd appreciate your vote for Telerik in this year's DevProConnections Awards. We are competing in mind-blowing 20 categories and every vote counts! VOTE for Telerik NOW >>

Tags
General Discussions
Asked by
Developer Developer
Top achievements
Rank 1
Answers by
Tsvetina
Telerik team
Share this question
or