Dhaval Shukla
Dhaval Shukla

Reputation: 1127

$find returning null

I have radGrid in .ascx page in which I want to find the control using $find but it returns a null to me. Below is my code which I am using to get the object (written in .ascx).

<script type="text/javascript">
    $(function () {
        var Rates_gridID = $find('<%= gridRates.ClientID %>');
        alert(Rates_gridID);
    });
</script>

Here, I am getting Rates_gridID as null in alert. Interesting thing which I noted is when I change the jQuery version to 1.2.6 from 1.6.4 I am getting Rates_gridID object. I have googled this a lot but not getting any solution. I think the problem is with $(function().

Upvotes: 0

Views: 6336

Answers (4)

Alaa.Kh
Alaa.Kh

Reputation: 151

$find is differ from $.find. The first one is provides a shortcut to the findComponent method of the Sys.Application class which defined by the Microsoft AJAX Library. while the second is API method from jQuery which get the descendants of each element in the current set of matched elements, filtered by a selector, jQuery object, or element.

So, $find has to find Component not html DOM. and ajax Library has to be defined.

For more information: http://msdn.microsoft.com/en-us/library/vstudio/bb397441(v=vs.100).aspx http://api.jquery.com/find/

Upvotes: 3

Kanishka Panamaldeniya
Kanishka Panamaldeniya

Reputation: 17576

what is $find here . it is incorrect.

use it like

$("body").find('<%= gridRates.ClientID %>');

see more about find() in

http://api.jquery.com/find/

Description: Get the descendants of each element in the current set of matched elements, filtered by a selector, jQuery object, or element

Upvotes: 1

arunes
arunes

Reputation: 3524

If <%=gridRates.ClientID%> is unique id you should use like this

var Rates_gridID = $("#<%=gridRates.ClientID%>");
alert(Rates_gridID);

Upvotes: -1

Starx
Starx

Reputation: 78981

You are using the incorrect syntax. Try

$("body").find('<%= gridRates.ClientID %>');

Upvotes: 3

Related Questions