Page-level property to detect an Ajax callback

Thread is closed for posting
4 posts, 0 answers
  1. 26A36C3F-BBCA-4686-9656-0E0B87041A1C
    26A36C3F-BBCA-4686-9656-0E0B87041A1C avatar
    22 posts
    Member since:
    May 2006

    Posted 12 Jun 2006 Link to this post

    Requirements

    r.a.d.controls version

    Any Telerik control

    .NET version

    2.0

    Visual Studio version

    2003/2005

    programming language

    C#

    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
    {
        get
        {
            HttpContext ctx = HttpContext.Current;

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

  2. 3BD6F94B-4C03-46D3-8568-9982F1F201BF
    3BD6F94B-4C03-46D3-8568-9982F1F201BF avatar
    10940 posts
    Member since:
    May 2014

    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,

    Steve
    the telerik team
  3. 918BDF93-DAC5-457C-BCCD-71E4B1EA327C
    918BDF93-DAC5-457C-BCCD-71E4B1EA327C 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
                Get
                    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
                Next
            End Function
  4. 030B5A59-D59A-466C-BF7E-5FB47F06BBD4
    030B5A59-D59A-466C-BF7E-5FB47F06BBD4 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.

    Cheers!

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

    ctx.Request.Form["RadAJAXControlID"]!=null

Back to Top

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