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

One-way ajax

3 Answers 56 Views
Ajax
This is a migrated thread and some comments may be shown as answers.
Valera
Top achievements
Rank 1
Valera asked on 01 Nov 2011, 09:46 PM
Hello,

I would like to know if it is possible to create "one-way" ajax request?

Example of the scenario:
By clicking a button, web page send an email... there is no GUI changes on the page.

Currently I use RadAjaxManager with following syntax:
manager.AjaxSettings.AddAjaxSetting(btnSendEmail, btnSendEmail);

As you can see, in order to AddAjaxSetting, I need to specify AjaxTrigger control and AjaxifiedCntrol (in this case they are the same controls).

But I was wondering if I could only specify AjaxTrigger control, without specifying a control that is being updated?

I'm looking to improve page responsiveness to "one-way" ajax requests...

3 Answers, 1 is accepted

Sort by
0
Marin
Telerik team
answered on 02 Nov 2011, 10:50 AM
Hi Valera,

 When you add an ajax setting to the RadAjaxManager it wraps the button in a update panel, and specifies that the button itself will be the initiator of the asynchronous request. The content in the update panel is changed only if the server returns a different HTML response. So in this case there is no one-way or two-way ajax request. The ajax request is only one and it is triggered when you click the button. This is the way that all the ASP.NET update panels work. They specify a control that will trigger the request and an area wrapped in the update panel that can possibly be changed if the server returns different response.
Alternatively you can manually trigger an ajax request from the client and handle it on the server, this way you will not need to specify ajax settings for the button. More information on how to do this is available in this help topic:
http://www.telerik.com/help/aspnet-ajax/ajax-onajaxrequest.html

Regards,
Marin
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now
0
Kevin
Top achievements
Rank 2
answered on 02 Nov 2011, 01:36 PM
Hello Valera,

You don't really need to use an Ajax request to perform an asynchronous request. You could use a callback instead, which should increase performance as it doesn't run through the whole page lifecycle like Ajax does. So it could look something like this:

Code-Behind:
public partial class _Default : System.Web.UI.Page, ICallbackEventHandler 
    protected void Page_Load(object sender, EventArgs e) 
    
    
    
    // hold callback return value 
    string returnValue; 
    
    public string GetCallbackResult() 
    
        return returnValue; 
    
    
    public void RaiseCallbackEvent(string args) 
    
              // send email and determine if email was sent or not
              bool emailSent = SendEmail();
  
              if(emailSent) 
              {
                  returnValue = "Email Sent";
              }
              else
              {
                  returnValue = "Email Not Sent"
              }
    
}

JS:
function SendEmail(arg) { 
            try
                      // call callback
                     <%=Page.ClientScript.GetCallbackEventReference(this, "arg", "ReceiveResult", "null") %>; 
            
            catch (e) { 
            
        
        function ReceiveHitResult(value) { 
            alert(value);
        }

All you need to do then is attach the SendEmail function to the button click event to perform the callback. I'm showing an alert when the callback finishes to alert the user if the email was sent or not. You don't need to do anything in the ReceiveResult method, you can leave it empty if you want.

I hope that helps.
0
Valera
Top achievements
Rank 1
answered on 02 Nov 2011, 09:40 PM
Thank You -

Using Callback addresses my problem perfectly!
Tags
Ajax
Asked by
Valera
Top achievements
Rank 1
Answers by
Marin
Telerik team
Kevin
Top achievements
Rank 2
Valera
Top achievements
Rank 1
Share this question
or