I'm currently working on an AJAXified application which needs the occasional regular postback performed, and I ran across an oddity which I'm trying to understand.
In the client-side OnRequestStart, two arguments are returned, sender and eventArgs. "sender" corresponds to the RadAjaxManager which initiated the call; eventArgs contains references to what was actually clicked to start the request.
Naturally, the sender possesses all the properties of the page's RadAjaxManager, including set_enableAJAX, which, if called, according to the documentation, "Allows or blocks the request to be executed through AJAX. Pass True to allow AJAX, False to have the request fulfilled through a standard postback."
The eventArgs, however, also possesses its own personal properties, one of which is set_enableAjax - different case - which, according to the documentation, "sets if an AJAX request is performed. set_enableAjax(false) causes the request to be performed via standard postback."
At face value, both of these functions would seem to do the same thing. However, in experimentation (and I have no idea whether or not this applies beyond my own experience) they appear to be slightly different in scope: set_enableAJAX(false) turns off AJAX for the entire page once the initial AJAX request completes, and every call after that is a postback; while set_enableAjax(false) turns off AJAX for a single request, immediately.
This would explain a number of issues I've been having with getting AJAX requests to postback, but it may very well be that I'm mistaken - the documentation definitely doesn't imply a difference on first reading.
Some sample code:
The following Javascript works as expected: the request is submitted as a postback immediately.
The following Javascript code does not work as expected: the first request is submitted as AJAX, receiving an invalid AJAX error (there are Response.Writes in the codebehind), but all subsequent requests through that control are postbacks, as expected.
The code works now; I just want to know whether I've misunderstood the documentation or am completely mistaken about the reasons for these results. Make sense?
My best guess is that set_enableAJAX refers to the global setting of the RadAjaxManager rather than the setting of the current request. Let me know if I'm understanding that correctly!
In the client-side OnRequestStart, two arguments are returned, sender and eventArgs. "sender" corresponds to the RadAjaxManager which initiated the call; eventArgs contains references to what was actually clicked to start the request.
Naturally, the sender possesses all the properties of the page's RadAjaxManager, including set_enableAJAX, which, if called, according to the documentation, "Allows or blocks the request to be executed through AJAX. Pass True to allow AJAX, False to have the request fulfilled through a standard postback."
The eventArgs, however, also possesses its own personal properties, one of which is set_enableAjax - different case - which, according to the documentation, "sets if an AJAX request is performed. set_enableAjax(false) causes the request to be performed via standard postback."
At face value, both of these functions would seem to do the same thing. However, in experimentation (and I have no idea whether or not this applies beyond my own experience) they appear to be slightly different in scope: set_enableAJAX(false) turns off AJAX for the entire page once the initial AJAX request completes, and every call after that is a postback; while set_enableAjax(false) turns off AJAX for a single request, immediately.
This would explain a number of issues I've been having with getting AJAX requests to postback, but it may very well be that I'm mistaken - the documentation definitely doesn't imply a difference on first reading.
Some sample code:
| <telerik:RadAjaxManager ID="RadAjaxManager1" runat="server" OnAjaxRequest="RadAjaxManager1_AjaxRequest"> |
| <AjaxSettings> |
| <telerik:AjaxSetting AjaxControlID="RadAjaxManager1"> |
| <UpdatedControls> |
| <telerik:AjaxUpdatedControl ControlID="LoadingPanel" LoadingPanelID="RadAjaxLoadingPanel1" /> |
| </UpdatedControls> |
| </telerik:AjaxSetting> |
| </AjaxSettings> |
| <ClientEvents OnRequestStart="fnTestPostback" /> |
| </telerik:RadAjaxManager> |
The following Javascript works as expected: the request is submitted as a postback immediately.
| function fnTestPostback(sender, args) { |
| try { |
| if (args.EventTarget.indexOf("SubmitAndGenerate") != -1) { |
| args.set_enableAjax(false); |
| return true; |
| } |
| } |
| catch (ex) { |
| alert("Error overriding postback: "+ex.message); |
| } |
| } |
The following Javascript code does not work as expected: the first request is submitted as AJAX, receiving an invalid AJAX error (there are Response.Writes in the codebehind), but all subsequent requests through that control are postbacks, as expected.
| function fnTestPostback(sender, args) { |
| try { |
| if (args.EventTarget.indexOf("SubmitAndGenerate") != -1) { |
| sender.set_enableAJAX(false); |
| return true; |
| } |
| } |
| catch (ex) { |
| alert("Error overriding postback: "+ex.message); |
| } |
| } |
The code works now; I just want to know whether I've misunderstood the documentation or am completely mistaken about the reasons for these results. Make sense?
My best guess is that set_enableAJAX refers to the global setting of the RadAjaxManager rather than the setting of the current request. Let me know if I'm understanding that correctly!