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

[bug] $find return null

3 Answers 172 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Robin
Top achievements
Rank 1
Robin asked on 03 Jul 2011, 01:08 PM
Hi,

I'm having an issue with ASP.NET AJAX Q1 2011.

The code is very simple: I want to add a client validation function to the button save dynamically. The code is put inside JQ block 

$(document).ready(function () {
// buttonSaveClientID is defined already
$find(buttonSaveClientID).add_clicking(validationFunction);
});

There are 2 buttons on my web form: Save & Reset (which just causes a postback). When I do postback several times, the fireBug shows that $find(buttonSaveClientID) is null.

It happens occasionally. Most time the code run ok. Sometime it failed.

Do you have any idea?

Moreover, I'm guessing that it may be caused by telerik script is not finished processing. So I do a hook:

for (var i = 0; i < 1000000; i++) {
if ($find(buttonSaveClientID))
break;
}
$find(buttonSaveClientID).add_clicking(validationFunction);

and it works. Do you know how to check if telerik script is finished processing instead of such type of work around?

3 Answers, 1 is accepted

Sort by
0
Accepted
Georgi Tunev
Telerik team
answered on 04 Jul 2011, 11:24 AM
Hi Robin,

Try using the pageLoad() function instead of document.ready when you are working with ASP.NET AJAX controls. More information on both events can be found in various resources on the Net. For example, you could check this article:

http://encosia.com/document-ready-and-pageload-are-not-the-same/

Regards,
Georgi Tunev
the Telerik team

Browse the vast support resources we have to jump start your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.

0
Robin
Top achievements
Rank 1
answered on 05 Jul 2011, 07:07 PM
Many thanks for your great help.

No more error. Unbelievable that is so simple.

But I wonder why jQuery has not fixed it?!
0
Georgi Tunev
Telerik team
answered on 06 Jul 2011, 11:24 AM
Hello Robin,

I am glad I was able to help. As for why this is not fixed in jQuery - actually, this is not a bug. In jQuery, ready() is raised as soon as the DOM hierarchy has been fully constructed. ASP.NET AJAX's pageLoad() is called on different stage - when all ASP.NET AJAX controls (including the ones from our ASP.NET AJAX suite) are rendered on the page.


Kind regards,
Georgi Tunev
the Telerik team

Register for the Q2 2011 What's New Webinar Week. Mark your calendar for the week starting July 18th and book your seat for a walk through of all the exciting stuff we will ship with the new release!

Tags
General Discussions
Asked by
Robin
Top achievements
Rank 1
Answers by
Georgi Tunev
Telerik team
Robin
Top achievements
Rank 1
Share this question
or