$find returns null if the Menu is in a UserControl

4 posts, 0 answers
  1. Thomas Luck
    Thomas Luck avatar
    38 posts
    Member since:
    Jun 2006

    Posted 18 Oct 2011 Link to this post

    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
  2. Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 19 Oct 2011 Link to this post

    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.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Thomas Luck
    Thomas Luck avatar
    38 posts
    Member since:
    Jun 2006

    Posted 19 Oct 2011 Link to this post

    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
  5. Kate
    Admin
    Kate avatar
    1898 posts

    Posted 21 Oct 2011 Link to this post

    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
Back to Top