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

$find not working

6 Answers 277 Views
PanelBar
This is a migrated thread and some comments may be shown as answers.
Eduardo
Top achievements
Rank 1
Eduardo asked on 20 May 2009, 02:51 PM
Hi,

Am I missing something? The $find is not working for a RadPanelBar, here is the code:

... 
<body topmargin="0" leftmargin="0"
    <form id="form1" runat="server"
    <div> 
        <telerik:RadScriptManager ID="RadScriptManager1" runat="server"
        </telerik:RadScriptManager> 
        <telerik:RadPanelBar ID="rpbNavigation" runat="server" style="width:100%" Skin="Outlook" EnableViewState="false"
        </telerik:RadPanelBar> 
    </div> 
    </form> 
    <telerik:RadCodeBlock ID="RadCodeBlock2" runat="server"
        <script type="text/javascript"
            checkMain(); 
            function checkMain() { 
                var panelBar = $find("<%= rpbNavigation.ClientID %>"); 
 
                var item = panelBar.findItemByText(Main.selectedModule); 
            } 
        </script> 
    </telerik:RadCodeBlock> 
</body> 
... 

I tried to put the script block on the header tag and in the body tag. If I replace by $get, it works, but then I can't access the findItemByText function. The funny thing is that I use a very similar code on other page and it works, the difference is that I use a RadMenu instead a RadPanelBar.

On, the call to checkMain() would be on the onload event of the body, I tried to move around to see if there was something to do with the timing of this call, but no luck.

Any help is appreciated.

Thanks,
Eduardo

6 Answers, 1 is accepted

Sort by
0
Accepted
Shinu
Top achievements
Rank 2
answered on 21 May 2009, 04:36 AM
Hello Eduardo,

In ASP.NET AJAX environment, the ASP.NET AJAX controls (including RadControls for ASP.NET AJAX) are created after the page has been loaded. That's why you are not getting client side object of RadPanelBar. In order to get the client side object of RadControls when page loads, you can create function that use the reserved name pageLoad() (which fires when page loads) and inside that you can access the client side object for each control. Try the following approach.

JavaScript:
 
<script type="text/javascript"
function pageLoad() 
    checkMain();  
function checkMain() 
{  
    var panelBar = $find("<%= rpbNavigation.ClientID %>"); 
    var item = panelBar.findItemByText('TextToFind');  
    alert(item.get_text()); 
}  
</script> 

Regards,
Shinu.
0
Eduardo
Top achievements
Rank 1
answered on 21 May 2009, 01:40 PM
Thanks a lot, you are a genius :-)

Eduardo
0
tmlipinski
Top achievements
Rank 1
answered on 25 May 2009, 09:49 AM
Hi,

It is the first time I've learnt about "pageLoad" reserved function name. Where does it come from? Is this reserved name (and other reserved names of this kind?) described anywhere? I've tried to "google" it but with no success.
The same applies to the $find function.

Can you link me to any kind of documentation of that?
Thank you in advance.

Regards
Tomasz
0
Paul
Telerik team
answered on 25 May 2009, 10:15 AM
Hi Tomasz,

pageLoad() is a shortcut for the Sys.Application.load event. For details on the matter please refer to the following ASP.NET article.

Regards,
Paul
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
0
tmlipinski
Top achievements
Rank 1
answered on 25 May 2009, 10:24 AM
Thanks a lot.
Tomasz
0
Lorenzo
Top achievements
Rank 1
answered on 08 Mar 2011, 07:41 PM
I agree with Eduardo...you are a genius !!!!!

Thanks
Tags
PanelBar
Asked by
Eduardo
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Eduardo
Top achievements
Rank 1
tmlipinski
Top achievements
Rank 1
Paul
Telerik team
Lorenzo
Top achievements
Rank 1
Share this question
or