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

Is there a need to serialize calls?

3 Answers 55 Views
Ajax
This is a migrated thread and some comments may be shown as answers.
ManniAT
Top achievements
Rank 2
ManniAT asked on 22 Apr 2009, 10:24 AM
Hi,

I currently fight with a problem handling RadFileExplorer.
While there are other problems it brings me to a general question - is there a need to serialize ajax calls.

I use sample code from RadFileExplorer - but the question is a general question.
function OnClientSomeControlDidSomething(sender, args) {  
    TellServerAboutSelectedElement("Someparam");  
}  
 
function TellServerAboutSelectedElement(argument) {  
    var ajaxManager = $find("<%= RadAjaxManager.GetCurrent(Page).ClientID %>");  
    ajaxManager.ajaxRequest(argument);  
}  
 
Assume this OnClientSomeControlDidSomething is fired by a control which fires this event immediately after it fired an ajax call.
As with FileExplorer - it fires something like "AjaxLoadTheFolderContent" followed by OnClientFolderChange.
So if loading of the changed folder takes time my handler starts an ajax call while an other ajax call (LoadFolderContent) is in progress.

So the general question - does it make problems (or is it even allowed) to make an ajax call while another ajax call is in progress?
I'm not talking about potential problems (who wins if controls need to be updated) - I just wanna know if this is allowed or not.

If the answer is: NO it is not allowed you have to make the calls one after another if have a second problem.

OnResponseEnd and OnRequestStart are two functions available on the AjaxManager. But there is no "extra version" for the AjaxProxy.
Assume I have to serialize calls and I use MasterPages where the AjaxManager resides in the masterpage while AjaxProxies are used in the DetailPages - and to make it really hard - I use UserControls - also with AjaxProxy.
Assume further the MasterPage has a need to handle the OnResponseEnd - my page needs special handling also and finally my UserControl has a need for those events.

Since these eventhandler are not events like C# events where I add a handler (additional to existing ones) I can only have one of these handlers at a time.
Of course I could do some "Magic" by finding out if an event is already bound and then emit my handler jscript from server like this:
string strExistingHanlder = aM.ClientEvents.OnResponseEnd;  
string strMyHandler;  
if (!string.IsNullOrEmpty(strExistingHanlder)) {  
    strMyHandler = "function OnMyResponseEnd(sender,args) {";  
    strMyHandler += strExistingHanlder + "(sender, args); DoMyHandling(sender, args); }";  
}  
else {  
    strMyHandler = "function OnMyResponseEnd(sender,args) {  DoMyHandling(sender, args); }";  
}  
 
As long as I take care about my Handler function name it should work - but is this a good solution, or is there a "how to do this properly" for "chaining" handlers?

Regards

Manfred

3 Answers, 1 is accepted

Sort by
0
ManniAT
Top achievements
Rank 2
answered on 22 Apr 2009, 01:54 PM

Follow up -- I know (what's in documentation) about http://www.telerik.com/help/aspnet-ajax/ajxrequestqueuesize.html - but setting the size does not change anything!

At least with FileExplorer.

To be sure (documentation says nothing more) - simply setting the number to some useful value is enough to enable this feature, or is there something else to do?
0
Accepted
Tsvetoslav
Telerik team
answered on 24 Apr 2009, 08:50 AM
Hello ManniAT,

1. Concerning your first question - if you make an ajax request while a previous one is still being carried out, the latter will be canceled.  The documentation article you have looked at is correct and there are no other requirements for queueing ajax calls apart from assigning a valid value to the RequestQueueSize property of the RadAjaxManager.

2. With regards to your second question - you do not need to add event handlers to the RadAjaxManager events in question to achieve your scenario. The easiest way is:
 
1  To leave the ajax manager on the master page;
2. Attach event handlers to the events you are interested in;
3. In your user controls and content pages write the client methods to execute your custom logic.
4. In the event handlers for the events of RadAjaxManager on the master page call the client methods from the user controls and detail pages.

I hope this information helps.
 

Regards,
Tsvetoslav
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
ManniAT
Top achievements
Rank 2
answered on 24 Apr 2009, 09:11 AM
Hi,

thank you for the answer.
About point 3 and 4 I think a bit different. It would work - your are right - but this means that (I an OO thinking) the base class hast to know implementation details about their (not jet existing) derived classes.
A solution (that fits your approach) would be an abstract base class which forces their derived classes to implement certain methods.
BUT - we are not in an object oriented world in this case - so chaining seems to be the better approach for me.

And it is not an uncommon approach - hooking is still a thing that exists :)
I did some WoW Addons (LUA) where you also have to hook functions - and this looks very similar:
oldHandler=someObject.handler
someObject.handler=myHandler
--and in the code of myHandler
if(oldHandler) oldHandler(....)

Last not least it gives a nostalgic feeling remembering me at the "good old times" where programming windows looks also like this in some cases :)

Anyhow - thanks for your clear answers - and the problem (I guess) is related to FileExplorer because with other controls the things work as expected - only FileExplorer seems to use it's own way, which bypasses OnResponseEnd (and OnRequestStart).

Regards

Manfred
Tags
Ajax
Asked by
ManniAT
Top achievements
Rank 2
Answers by
ManniAT
Top achievements
Rank 2
Tsvetoslav
Telerik team
Share this question
or