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

$find returns null if the Menu is in a UserControl

3 Answers 132 Views
Menu
This is a migrated thread and some comments may be shown as answers.
Thomas Luck
Top achievements
Rank 1
Thomas Luck asked on 18 Oct 2011, 03:25 PM
hey

I've a little problem with the js function $find...
The Menu used in the UserControl XY
I try to get the client object of the Menu with $find("<%=XYObject.InnerMenu.ClientId %>") but it returns null
so I've tried the function $get which worked...  the readyState is also 'complete'...
When I add the Menu directly without the UserControl it's working....

Greetings

3 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 19 Oct 2011, 08:55 AM
Hello Thomas,

Here is a sample code to access the child control.
Javascript:
<script type="text/javascript">
function accesUserControl()
    {
         var menu = $get('<%=WebUserControl1.FindControl("RadMenu1").ClientID%>');
    }
</script>

Thanks,
Shinu.
0
Thomas Luck
Top achievements
Rank 1
answered on 19 Oct 2011, 10:07 AM
the InnerMenu property is the RadMenu....
and this is working fine with $get
$get('<%= WebUserControl.InnerMenu.ClientID %>')


the problem is that this isn't working with the $find function
0
Kate
Telerik team
answered on 21 Oct 2011, 01:35 PM
Hello Thomas,

The find function is working as expected but the reason why you are not able to find the RadMenu control is because its client ID renders in a different way when the RadMenu is placed first in a content page then in a user control. For example here is how the ID of the menu in user control would look like when it is placed in a content page. 
function pageLoad(sender, args) {
            var menu = $find("ctl00_ContentPlaceHolder1_MenuControl1_RadMenu1");
            alert(menu);
        }

I also attached my test page for your reference.

All the best,
Kate
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now
Tags
Menu
Asked by
Thomas Luck
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Thomas Luck
Top achievements
Rank 1
Kate
Telerik team
Share this question
or