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

[Solved] set_enableAJAX question

1 Answer 538 Views
Ajax
This is a migrated thread and some comments may be shown as answers.
AJtheCoder
Top achievements
Rank 1
AJtheCoder asked on 12 May 2008, 06:25 PM
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:

      <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!

1 Answer, 1 is accepted

Sort by
0
Steve
Telerik team
answered on 13 May 2008, 07:48 AM
Hi ADH,

Indeed the explanation of the set_enableAJAX() in our documentation is a bit confusing and we will change it immediately. Your understanding of both properties are correct and there is no misunderstanding.
Your Telerik points have been updated for pointing this out. Do let us know if you notice other confusing statements in our docs.

Sincerely yours,
Steve
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
Tags
Ajax
Asked by
AJtheCoder
Top achievements
Rank 1
Answers by
Steve
Telerik team
Share this question
or