AjaxManager NULL when called from a callback;

20 posts, 0 answers
  1. Ben Turpin
    Ben Turpin avatar
    27 posts
    Member since:
    Jun 2008

    Posted 09 Sep 2008 Link to this post

    Hi!

    Im trying do a ajax request with the ajaxmanager from a callback function, but the ajaxmanager is null when called form the callback. A simple test can be made.

    Do the request, in the callback handler do another request as follow:

            function PressMe() 
            { 
                SendRequest("From Press Me"); 
            } 
             
            function SendRequest(message) 
            { 
                var ajaxManager = $find("RadAjaxManager1"); 
                ajaxManager.ajaxRequest(message); 
            } 
             
            function RequestCallback() 
            { 
                //setTimeout("SendRequest('From Callback');",0); 
                SendRequest("From Callback"); 
            }

    The first time the 'SendRequest' is called it finds the ajaxManager and does the request. Then the RequestCallBack is called from the server-side :

          protected void RadAjaxManager1_AjaxRequest(object sender, Telerik.Web.UI.AjaxRequestEventArgs e) 
    {
       RadAjaxManager1.ResponseScripts.Add("RequestCallback();"); 

    It adds the script and calls the client-side 'RequestCallback' funtion and sends now the second request, but this time the ajaxaManager object is null!
    The intresting fact is that if I do a time out with 0 milisecond wait ( commentded code ) it finds the ajaxManager.

    Maybe something with the context of this ResponseScripts? Any ideas?

    Thanks.
  2. Iana Tsolova
    Admin
    Iana Tsolova avatar
    3388 posts

    Posted 12 Sep 2008 Link to this post

    Hi Ben Turpin,

    I followed the steps you describe for reproducing the issue but no avail. Please find the attached sample let me know how it works on your end and if I missed something from your logic.

    Kind regards,
    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
  4. damien jorgensen
    damien jorgensen avatar
    10 posts
    Member since:
    Oct 2005

    Posted 04 Oct 2008 Link to this post

    I also am getting this problem
  5. Sebastian
    Admin
    Sebastian avatar
    9934 posts

    Posted 06 Oct 2008 Link to this post

    Hi damien,

    Have you reviewed the sample project posted by my colleague Iana in this thread? I will appreciate if you outline the differences between your case and the one presented in the demo. They can help us track down the source of the problem to eliminate it asap.

    Kind regards,
    Stephen
    the Telerik team

    Check out Telerik Trainer, the state of the art learning tool for Telerik products.
  6. damien jorgensen
    damien jorgensen avatar
    10 posts
    Member since:
    Oct 2005

    Posted 06 Oct 2008 Link to this post

    I have a master page

    The ASPX page is where the RADManager resides

    On trying to access the RADManager via javascript it always returns a null.

    I have switched to using an updatepanel and a hidden button to emulate the AJAXRequest but clearly it isnt such a nice solution.


  7. damien jorgensen
    damien jorgensen avatar
    10 posts
    Member since:
    Oct 2005

    Posted 06 Oct 2008 Link to this post

    This also appears to return a null

     

    var currentLoadingPanel = $find("RadAjaxLoadingPanel1");
    currentLoadingPanel.show(currentUpdatedControl);

     

  8. Iana Tsolova
    Admin
    Iana Tsolova avatar
    3388 posts

    Posted 06 Oct 2008 Link to this post

    Hi damien,

    Is your javascript placed in the same ContentPalceHolder where the RadAjaxManager and the RadAjaxaLoadingPanel reside?

    Please find the attached sample and let me know how it works on your end.

    Find more about RadAjax client-side API in the following resources:
    http://www.telerik.com/help/aspnet-ajax/ajxclientsideapi.html
    http://www.telerik.com/help/aspnet-ajax/ajxradajaxmanagerclientobject.html
    http://www.telerik.com/help/aspnet-ajax/ajxshowhideloadingpanel.html

    Sincerely yours,
    Iana
    the Telerik team

    Check out Telerik Trainer, the state of the art learning tool for Telerik products.
  9. Nate Pinchot
    Nate Pinchot avatar
    59 posts
    Member since:
    Jan 2008

    Posted 13 Oct 2008 Link to this post

    I would like to confirm the problem that Ben Turpin pointed out in his original post. This problem does indeed exist.

    If you attempt to use the RadAjaxManager from a function that is called from codebehind by using RaxAjaxManager1.ResponseScripts.Add, the $find function will return null for the RadAjaxManager1.

    I worked around this problem by using a setTimeout as Ben described.

    However the issue still remains. A fix for this would be much appreciated.

    Edit: I am using the latest version available of the controls.
  10. Iana Tsolova
    Admin
    Iana Tsolova avatar
    3388 posts

    Posted 14 Oct 2008 Link to this post

    Hello Nate,

    Have you tried any of the samples posted here? You can also review this topic about ajax requests queueing.

    I hope this helps.

    Regards,
    Iana
    the Telerik team

    Check out Telerik Trainer, the state of the art learning tool for Telerik products.
  11. Nate Pinchot
    Nate Pinchot avatar
    59 posts
    Member since:
    Jan 2008

    Posted 14 Oct 2008 Link to this post

    Hello Iana,
    Please add the response script add to the Page_Load procedure from the sample you posted on 9/12/2008 and you will see the issue I am facing. The $find("RadAjaxManager1") will return null.

    protected void Page_Load(object sender, EventArgs e) 
        RadAjaxManager1.ResponseScripts.Add("RequestCallback();"); 

    The reason I need to be able to do this is because I am trying to reconstruct a previous client state using data from the url. In order to accomplish this I use the RadAjaxManager client side ajaxRequest method.
  12. Iana Tsolova
    Admin
    Iana Tsolova avatar
    3388 posts

    Posted 15 Oct 2008 Link to this post

    Hello Nate,

    I followed you steps and replicated the behavior. However you can try the following sample which also reproduces the error:

    aspx
    <script type="text/javascript">  
    function RequestCallback()    
    {  
        var btn = $find("Button1");  
        alert(btn);  
    }  
    </script> 
    <telerik:RadAjaxManager ID="RadAjaxManager1" runat="server">  
    </telerik:RadAjaxManager> 
    <asp:Button ID="Button1" runat="server" Text="Button" /> 

    cs
    protected void Page_Load(object sender, EventArgs e)  
    {          
        RadAjaxManager1.ResponseScripts.Add("RequestCallback();");  
    }   

    For me this means that the page controls are not truly initialized when the client code is executed. That is why we need to set timeout, even be it zero, to make sure the controls are initialized before execution.

    Kind regards,
    Iana
    the Telerik team

    Check out Telerik Trainer, the state of the art learning tool for Telerik products.
  13. Nate Pinchot
    Nate Pinchot avatar
    59 posts
    Member since:
    Jan 2008

    Posted 15 Oct 2008 Link to this post

    Iana,
    Thanks for duplicating the problem.
    I'm a little confused why you would say that setTimeout with a wait of 0 will wait until the controls are initialized when setTimeout 0 is not going to wait at all. That doesn't seem right to me, but if what you say is true, then setTimeout will fail on slower systems - because it will take longer for the controls to initialize. So I need a more solid solution.
    How can I tell ResponseScripts.Add to add the script to the page so that it runs after the controls are initialized? I would like to have a solid solution for this. Please help.
  14. Iana Tsolova
    Admin
    Iana Tsolova avatar
    3388 posts

    Posted 16 Oct 2008 Link to this post

    Hi Nate,

    However timeout of zero provided enough delay for the function execution to happen after client-side objects creation, in case you prefer not to rely on the timeout, I suggest that you use the ScriptManager RegisterStartupScript static method. The startup scripts are always executed after client-side object creation and thus you should care about fast and slower systems.

    I hope this helps.

    Kind regards,
    Iana
    the Telerik team

    Check out Telerik Trainer, the state of the art learning tool for Telerik products.
  15. Nate Pinchot
    Nate Pinchot avatar
    59 posts
    Member since:
    Jan 2008

    Posted 16 Oct 2008 Link to this post

    Hi Iana,
    Did you test your suggestion?
    The same error happens when using the following code:

        protected void Page_Load(object sender, EventArgs e) 
        { 
            ScriptManager.RegisterStartupScript(thistypeof(Page), "callback""RequestCallback();"true); 
        } 

    It would appear that your theory about the controls not being initialized is not correct. Should I submit a bug report? I would really like to get this issue resolved and you are not even testing the advice you are giving me at this point which I must say is terrible customer service on your part.
  16. Iana Tsolova
    Admin
    Iana Tsolova avatar
    3388 posts

    Posted 17 Oct 2008 Link to this post

    Hello Nate

    What about modifying your code:

    protected void Page_Load(object sender, EventArgs e)  
    {  
       ScriptManager.RegisterStartupScript(thistypeof(Page), "callback""function pageLoad(){RequestCallback();}"true);   
    }    

    Iana
    the Telerik team

    Check out Telerik Trainer, the state of the art learning tool for Telerik products.
  17. Nate Pinchot
    Nate Pinchot avatar
    59 posts
    Member since:
    Jan 2008

    Posted 17 Oct 2008 Link to this post

    Iana,
    That worked perfectly - Thanks so much for your help!
  18. Nate Pinchot
    Nate Pinchot avatar
    59 posts
    Member since:
    Jan 2008

    Posted 19 Oct 2008 Link to this post

    Iana,
    That gave no errors but it didn't execute the code.
  19. Iana Tsolova
    Admin
    Iana Tsolova avatar
    3388 posts

    Posted 20 Oct 2008 Link to this post

    Hi Nate,

    It works ok on my end. Therefore I suggest that you open a formal support ticket and send us a sample project illustrating your real scenario. Thus I could better enter into the issues you are facing and try finding a resolution for you.

    Kind regards,
    Iana
    the Telerik team

    Check out Telerik Trainer, the state of the art learning tool for Telerik products.
  20. Nuno Oliveira
    Nuno Oliveira avatar
    10 posts
    Member since:
    Jan 2006

    Posted 06 Dec 2008 Link to this post

    Hi Iana,

    Could you please tell me what is the solution for this problem because i still cannot find the answer in this forum?

    Best regards

  21. Nate Pinchot
    Nate Pinchot avatar
    59 posts
    Member since:
    Jan 2008

    Posted 08 Dec 2008 Link to this post

    Nuno,
    I wrapped the code in a setTimeout to resolve the issue. Not technically a proper fix but it works around the problem.
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017