Page-level property to detect an Ajax callback

4 posts, 0 answers
  1. Milan Negovan
    Milan Negovan avatar
    22 posts
    Member since:
    May 2006

    Posted 12 Jun 2006 Link to this post


    r.a.d.controls version

    Any Telerik control

    .NET version


    Visual Studio version


    programming language


    browser support

    all browsers supported by r.a.d.controls

    Sometimes I need to know if a page is going through a normal postback or a callback. Although Rad controls have a property for this, IsCallback, I prefer a page property which does not get involved with any control directly.

    Simply add the following property to your page base class:

    public bool IsAjaxCallback
            HttpContext ctx = HttpContext.Current;

            return (
                 ctx != null &&
                 ctx .Request != null &&
                (ctx.Request.QueryString["rcbID"] != null || ctx.Request.Form["ctrlid"] != null));

  2. Steve
    Steve avatar
    10940 posts

    Posted 13 Jun 2006 Link to this post

    Hi Milan,

    Thank you for posting this demo application in our code library section. However can you please send us a sample project corresponding to the solution presented here. This is the main idea behind the code-library, so people can download a sample and see if it works as they expect.

    We appreciate your involvement!

    Kind regards,

    the telerik team
  3. Dan Avni
    Dan Avni avatar
    18 posts
    Member since:
    Apr 2005

    Posted 14 Jun 2006 Link to this post

    the code you suggested does not take into account other callbacks like the grid or treeview callbacks. i think this approach is better because it does not care about the posted data so if telerik changes the name of the parameter in the query string my code would still run

            Public ReadOnly Property IsAjaxCallback() As Boolean
                    Return IsAjaxCallbackRecursive(Me.Controls)
                End Get
            End Property
            Private Function IsAjaxCallbackRecursive(ByVal ContainedControls As System.Web.UI.ControlCollection) As Boolean
                For Each Ctl As System.Web.UI.Control In ContainedControls
                    If TypeOf Ctl Is Telerik.WebControls.CallbackControls.ICallbackControl Then
                        Dim CBProps As Telerik.WebControls.CallbackControls.ICallbackControl = CType(Ctl, Telerik.WebControls.CallbackControls.ICallbackControl)
                        If CBProps.IsCallback Then Return True
                    ElseIf TypeOf Ctl Is Telerik.WebControls.RadComboBox Then
                        If CType(Ctl, Telerik.WebControls.RadComboBox).IsCallBack Then Return True
                    ElseIf TypeOf Ctl Is Telerik.WebControls.RadGrid Then
                        If CType(Ctl, Telerik.WebControls.RadGrid).IsAsyncRequest Then Return True
                    ElseIf TypeOf Ctl Is Telerik.WebControls.RadTreeView Then
                        If CType(Ctl, Telerik.WebControls.RadTreeView).IsCallBack Then Return True
                    End If
                    'run recursive
                    If Ctl.Controls.Count > 0 Then
                        If IsAjaxCallbackRecursive(Ctl.Controls) Then
                            Return True
                        End If
                    End If
            End Function
  4. JohnC
    JohnC avatar
    77 posts
    Member since:
    Sep 2006

    Posted 18 Sep 2006 Link to this post

    Thank you Milan, exactly what I was looking for.  I can't imagine why there isn't some built in method or property in the RadManger to detect this on page load.


    P.S. for the record this is what worked for me using just RadAjaxManager on a form:


Back to Top

This Code Library is part of the product documentation and subject to the respective product license agreement.