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

AjaxManager NULL when called from a callback;

19 Answers 236 Views
Ajax
This is a migrated thread and some comments may be shown as answers.
Ben Turpin
Top achievements
Rank 1
Ben Turpin asked on 09 Sep 2008, 02:43 PM
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.

19 Answers, 1 is accepted

Sort by
0
Iana Tsolova
Telerik team
answered on 12 Sep 2008, 07:12 AM
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.
0
damien jorgensen
Top achievements
Rank 1
answered on 04 Oct 2008, 07:41 PM
I also am getting this problem
0
Sebastian
Telerik team
answered on 06 Oct 2008, 08:06 AM
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.
0
damien jorgensen
Top achievements
Rank 1
answered on 06 Oct 2008, 08:26 AM
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.


0
damien jorgensen
Top achievements
Rank 1
answered on 06 Oct 2008, 11:17 AM
This also appears to return a null

 

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

 

0
Iana Tsolova
Telerik team
answered on 06 Oct 2008, 12:51 PM
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.
0
Nate Pinchot
Top achievements
Rank 1
answered on 13 Oct 2008, 08:28 PM
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.
0
Iana Tsolova
Telerik team
answered on 14 Oct 2008, 10:04 AM
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.
0
Nate Pinchot
Top achievements
Rank 1
answered on 14 Oct 2008, 02:34 PM
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.
0
Iana Tsolova
Telerik team
answered on 15 Oct 2008, 02:44 PM
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.
0
Nate Pinchot
Top achievements
Rank 1
answered on 15 Oct 2008, 02:55 PM
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.
0
Iana Tsolova
Telerik team
answered on 16 Oct 2008, 12:40 PM
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.
0
Nate Pinchot
Top achievements
Rank 1
answered on 16 Oct 2008, 08:27 PM
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.
0
Iana Tsolova
Telerik team
answered on 17 Oct 2008, 12:33 PM
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.
0
Nate Pinchot
Top achievements
Rank 1
answered on 17 Oct 2008, 02:10 PM
Iana,
That worked perfectly - Thanks so much for your help!
0
Nate Pinchot
Top achievements
Rank 1
answered on 19 Oct 2008, 05:34 AM
Iana,
That gave no errors but it didn't execute the code.
0
Iana Tsolova
Telerik team
answered on 20 Oct 2008, 09:26 AM
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.
0
Nuno Oliveira
Top achievements
Rank 1
answered on 06 Dec 2008, 11:34 AM
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

0
Nate Pinchot
Top achievements
Rank 1
answered on 08 Dec 2008, 06:37 AM
Nuno,
I wrapped the code in a setTimeout to resolve the issue. Not technically a proper fix but it works around the problem.
Tags
Ajax
Asked by
Ben Turpin
Top achievements
Rank 1
Answers by
Iana Tsolova
Telerik team
damien jorgensen
Top achievements
Rank 1
Sebastian
Telerik team
Nate Pinchot
Top achievements
Rank 1
Nuno Oliveira
Top achievements
Rank 1
Share this question
or