RadAjax for ASP.NET AJAX

RadControls for ASP.NET AJAX

By default the AJAX Panel ajaxifies all controls placed inside. If you want to exclude a control from ajaxifying you can use one of the following approaches:

ScriptManager RegisterPostBackControl method.

An easy solution can be implemented through the ScriptManager's RegisterPostBackControl method. An example follows:

CopyASPX
<telerik:RadScriptManager ID="RadScriptManager1" runat="server">
</telerik:RadScriptManager>
<telerik:RadAjaxPanel ID="RadAjaxPanel1" runat="server">
    <asp:Button runat="server" ID="Button1" Text="Ajax" OnClick="Button_Click" />
    <asp:Button runat="server" ID="Button2" Text="Postback" OnClick="Button_Click" />
    <asp:Label ID="Label1" runat="server"></asp:Label>
</telerik:RadAjaxPanel>
Note

Note that this approach is not applicable when the page is ajaxified with RadAjaxManager.

Disable AJAX via the OnRequestStart event (RadAjaxPanel, RadAjaxManager)

Use OnRequestStart client-side event handler to determine the AJAX initiator and disable AJAX for the current request. The event is fired on each request so on the next one the same check will be performed. A similar implementation is often used in case of exporting from AJAXified Grid:

Export RadGrid content to Excel/Word/CSV/PDF with Ajax enabled

Note

Note that all controls added in the UpdatedControls collection in the AJAX Manager ajax settings would perform callback instead of postback. To exclude them from ajaxifying use the above approach.

Cancel the AJAX request on InitializeRequest event

This approach is suitable for canceling the ajax request in wide range of scenarios. Unlike the OnReqestStart event, the InitializeRequest will be triggered for both Telerik (RadAjaxManager, RadAjaxPanel) and ASP.NET (UpdatePanel) ajax controls.

CopyASPX
<telerik:RadScriptManager ID="RadScriptManager1" runat="server" />
<script type="text/javascript">
    Sys.WebForms.PageRequestManager.getInstance().add_initializeRequest(initRequest);
    function initRequest(sender, args)
    {
        if (args.get_postBackElement().id.indexOf("CONTROL_ID") != -1)
        {
            args.set_cancel(true);  //stop async request
            sender._form["__EVENTTARGET"].value = args.get_postBackElement().id.replace(/\_/g, "$");
            sender._form["__EVENTARGUMENT"].value = "";
            sender._form.submit();
            return;
        }
    }
</script>

Please note that you have to replace the CONTROL_ID string with the actual name of the control that triggers the AJAX request.

Add post back function manually

  1. Implement the realPostBack function into your aspx/ascx file
  2. Add a custom OnClick attribute to the control (Button in this case).
CopyASPX
<telerik:RadCodeBlock ID="codeblock1" runat="server">
    <script type="text/javascript">
        function realPostBack(eventTarget, eventArgument)
        {
            $find("<%= RadAjaxPanel1.ClientID %>").__doPostBack(eventTarget, eventArgument);
        }
    </script>
</telerik:RadCodeBlock>
<asp:Button ID="Button1" runat="server" Text="Button" />
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<telerik:RadScriptManager ID="RadScriptManager1" runat="server">
</telerik:RadScriptManager>
<telerik:RadAjaxPanel ID="RadAjaxPanel1" runat="server">
    <asp:LinkButton ID="LinkButton1" runat="server" Text="PostBack"></asp:LinkButton>
    <asp:LinkButton ID="LinkButton2" runat="server" Text="Ajax"></asp:LinkButton>
</telerik:RadAjaxPanel>

And in the code-behind (Page_Load event handler):

If you do not have a control that registers the __doPostBack function on the page you should add the following line in the Page_Load as well:

This will come handy when you want a single control to perform post-back for your scenario or you want to upload files from control in RadAjaxPanel.

Exclude Dynamically Loaded Controls

In case you are loading the user control dynamically, the code if (!Page.IsPostBack) in the example above in its Page_Load event handler is never executed. You can check for the attached OnClick event instead of the IsPostBack. For example:

See Also

Other Resources