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

$find() not finding my AjaxManager

1 Answer 176 Views
Ajax
This is a migrated thread and some comments may be shown as answers.
Nathan J Pledger
Top achievements
Rank 2
Nathan J Pledger asked on 26 Jan 2009, 01:33 PM
Hi,

I have the following AJAXManager:

        <telerik:RadAjaxManager ID="radAjaxManager" runat="server" EnableEmbeddedScripts="true" EnableAJAX="true" UpdatePanelsRenderMode="Block"
            <AjaxSettings> 
                <telerik:AjaxSetting AjaxControlID="pnlCheckingSystem"
                    <UpdatedControls> 
                        <telerik:AjaxUpdatedControl ControlID="pnlCheckingSystem" /> 
                    </UpdatedControls> 
                </telerik:AjaxSetting> 
                <telerik:AjaxSetting AjaxControlID="btnLogin"
                    <UpdatedControls> 
                        <telerik:AjaxUpdatedControl ControlID="pnlLoggingIn" /> 
                    </UpdatedControls> 
                </telerik:AjaxSetting> 
            </AjaxSettings> 
        </telerik:RadAjaxManager> 
 
 

... and I am trying to "find" it using code I lifted from http://demos.telerik.com/aspnet-ajax/Ajax/Examples/Manager/ClientSideAPI/DefaultCS.aspx using the $find() function: (this is just before the BODY close tag)

    <telerik:RadCodeBlock ID="RadCodeBlock1" runat="server"
     
        <script type="text/javascript" language="javascript"
            function InitiateAsyncRequest(argument) { 
                var ajaxManager = $find('<%= radAjaxManager.ClientID %>'); 
                if (ajaxManager) ajaxManager.ajaxRequest(argument); 
                else alert('Could not get control \'<%=radAjaxManager.ClientID %>\''); 
            } 
 
            InitiateAsyncRequest('clientCheck'); 
        </script> 
     
    </telerik:RadCodeBlock> 

Instead, radAjaxManager keeps coming back null (therefore displaying the alert). For your information, the control ID it displays is indeed 'ctl00_contentPlaceHolder_radAjaxManager', which does map to the rendered HTML:

    <div id="login"
        <h1>Login</h1> 
        <!-- 2008.3.1125.35 --><div id="ctl00_contentPlaceHolder_radAjaxManagerSU"
    <span id="ctl00_contentPlaceHolder_radAjaxManager" style="display:none;"></span> 
</div> 
 
 

By the way, what's the purpose of the RadCodeBlock? I got an exception suggesting I should add it.

1 Answer, 1 is accepted

Sort by
0
Iana Tsolova
Telerik team
answered on 28 Jan 2009, 03:22 PM
Hello Nathan,

Try modifying your script as below and see if it makes any difference:

    <telerik:RadCodeBlock ID="RadCodeBlock1" runat="server">       
           
        <script type="text/javascript" language="javascript">       
 
            var initialLoad = true;  
            function InitiateAsyncRequest(argument) {       
                var ajaxManager = $find('<%= radAjaxManager.ClientID %>');       
                if (ajaxManager) ajaxManager.ajaxRequest(argument);       
                else alert('Could not get control \'<%=radAjaxManager.ClientID %>\'');       
            }       
            function pageLoad(sender, eventArgs)     
            {     
                if(initialLoad){  
                     initialLoad = false;  
                     InitiateAsyncRequest('clientCheck');       
                }  
            }     
        </script>       
           
    </telerik:RadCodeBlock>      
 

It seems that your InitiateAsincRequest() method is being executed before the RadAjaxManager client object is initialized. Byexecuting the code on pageLoad(), we are sure it is already loaded.

And for further information about RadCodeBlock, check out this topic. 

I hope this helps.

Sincerely yours,
Iana
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
Tags
Ajax
Asked by
Nathan J Pledger
Top achievements
Rank 2
Answers by
Iana Tsolova
Telerik team
Share this question
or