$find() not finding my AjaxManager

2 posts, 0 answers
  1. Nathan J Pledger
    Nathan J Pledger avatar
    95 posts
    Member since:
    Apr 2006

    Posted 26 Jan 2009 Link to this post

    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.
  2. Iana Tsolova
    Admin
    Iana Tsolova avatar
    3388 posts

    Posted 28 Jan 2009 Link to this post

    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.
  3. UI for ASP.NET Ajax is Ready for VS 2017
Back to Top