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

[Solved] Force postback only on AjaxRequest

4 Answers 309 Views
Ajax
This is a migrated thread and some comments may be shown as answers.
Michael Dunbar
Top achievements
Rank 2
Michael Dunbar asked on 21 Jul 2009, 09:06 AM
Hi,

I would like to set EnableAjax to false on the AjaxManager but only when the request is triggered via the OnAjaxRequest property and not when every other Ajax request is called.

Example in the documentation states I can force a postback via:

function onRequestStart(sender, args) { 
            args.set_enableAjax(false); 
        }; 

This works fine but it will of course stop all my Ajax requests will it not?

I was hoping I could do:

function ajaxRequest() { 
            var ajaxManager = $find("<%= ajaxManager.ClientID %>"); 
            ajaxManager.set_enableAjax(false); 
        } 

or

protected void ajaxManager_AjaxRequest(object sender, AjaxRequestEventArgs e) 
    { 
        ajaxManager.EnableAJAX = false
 
        // then call server side code 
    }  

but neither seem to work. The former because the event does not exist and the latter because it is too late in the page lifecycle to set enable ajax to false. Any ideas how I achieve this please?








4 Answers, 1 is accepted

Sort by
0
Daniel
Telerik team
answered on 21 Jul 2009, 02:02 PM
Hello Michael,

Please note that OnAjaxRequest is an event, not a property. I'm not sure that I understand in which case you want to cancel the AJAX request. The code you posted below will cancel the request and will force a postback in all cases (no exceptions). To avoid this behavior you can use a simple check:
function onRequestStart(sender, args)  
{  
    if(someCondition) 
        args.set_enableAjax(false);  
}  

Best regards,
Daniel
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
Michael Dunbar
Top achievements
Rank 2
answered on 21 Jul 2009, 02:04 PM
How do you pass a condition in to say only if the event called is the on ajax request and not every other ajax call from the ajax manager?

I only want to force a postback when I raise the "ajax request" event via the client/server event on the ajax manager: http://www.telerik.com/help/aspnet-ajax/ajxclientsideapi.html

To explain further, I am using the code below to enable me to call a server side function from a client event:

// Handles the row double click event 
    function onRowDblClick(sender, args) { 
        var hdnFileGuid = document.getElementById('<%= hdnFileGuid.ClientID %>').value; 
        if (hdnFileGuid != "") { 
            ajaxRequest(hdnFileGuid); 
        } 
    } 
 
function ajaxRequest(fileGuid) { 
            var ajaxManager = $find("<%= ajaxManager.ClientID %>"); 
            ajaxManager.ajaxRequest(fileGuid); 
        } 

I do not want this to interfere with existing ajax settings I am using to control server side controls, but I have to force a postback to get the server side event called by the ajaxRequest javascript function to work.

I am only using the ajax manager for this as I don't know of any other way of calling a server side event from JavaScript.



0
Michael Dunbar
Top achievements
Rank 2
answered on 21 Jul 2009, 03:13 PM
Or looking at this from a different perspective, can I find the id of the control that initiates the callback in the onRequestStart javascript function? That could then be my condition as to whether or not to disable ajax.
0
Daniel
Telerik team
answered on 22 Jul 2009, 03:28 PM
Hello Michael,

I attached a simple project that demonstrates how to get the ajax target and ajax argument. You can use these properties to distinguish whether you want to force postback or not.

Let me know if I'm missing something.

Regards,
Daniel
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.
Tags
Ajax
Asked by
Michael Dunbar
Top achievements
Rank 2
Answers by
Daniel
Telerik team
Michael Dunbar
Top achievements
Rank 2
Share this question
or