New to Telerik UI for ASP.NET AJAXStart a free 30-day trial

ajaxRequest() method

Client-side method to trigger a partial PostBack/AJAX request using the Telerik WebForms AjaxManager component.

Usage

ajaxRequest(eventArgument) method takes one parameter.

Parameters

ParameterTypeDescription
eventArgumentstringThe string data you want to pass as along (e.g. text, JSON string, etc.)

Example

ASP.NET
<telerik:RadAjaxManager ID="RadAjaxManager1" runat="server" OnAjaxRequest="RadAjaxManager1_AjaxRequest">
</telerik:RadAjaxManager>

<telerik:RadButton runat="server" ID="RadButton1" Text="Make an AJAX Request" AutoPostBack="false" OnClientClicked="OnClientClicked" />

<telerik:RadScriptBlock ID="RadScriptBlock1" runat="server">
    <script>
        function OnClientClicked(){
            var ajaxManager = $find("<%= RadAjaxManager1.ClientID %>");
            // Trigger AJAX request without parameter
            ajaxManager.ajaxRequest('');

            // Trigger AJAX request with parameter
            ajaxManager.ajaxRequest('MyStringValue');

            // Trigger AJAX request with JSON string as parameter
            // JSON Object
            var jsonObject = {
                "field1": "value1",
                "field2": "value2",
                "field3": "value3",
            }
            // JSON String
            var jsonString = JSON.stringify(jsonObject);
            // Send JSON string as parameter
            ajaxManager.ajaxRequest(jsonString);
        }
    </script>
</telerik:RadScriptBlock>

If you send a JSON string, you can deserialize it to an object, see How to serialize and deserialize (marshal and unmarshal) JSON in .NET and Deserialize an Object - Newtonsoft

Access the values on Server

Upon making an AJAX Request the AjaxManager triggers its AjaxRequest Server-side event where the e.Argument will contain the parameter values.

Example

C#
protected void RadAjaxManager1_AjaxRequest(object sender, Telerik.Web.UI.AjaxRequestEventArgs e)
{
    RadAjaxManager ajaxManager = (RadAjaxManager)sender;
    
    // MyStringValue
    // '{\"field1\":\"value1\",\"field2\":\"value2\",\"field3\":\"value3\"}
    string myArgument = e.Argument; 


    if (myArgument == "MyString")
    {
        // do something
    }else
    {
        // In case deserializing JSON object
        try
        {
            // Deserialize myArgument
            // do the rest
        }
        catch (Exception ex)
        {
            // Handle the exception
            // or
            // send and alert back to the client using AjaxManager
            ajaxManager.Alert(string.Format("Error: {0}\n{1}", ex.Message, "Please review the JSON string and ensure it corresponds to the Object structure you want to Deserialize into."));
        }
    }
}

See Also