Skip Navigation LinksHome / Community & Support / Code Library / ASP.NET AJAX > General and Integration Projects > Page-level property to detect an Ajax callback

Page-level property to detect an Ajax callback

Feed from this thread
  • Milan Negovan avatar

    Posted on Jun 12, 2006 (permalink)

    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));
        }
    }

    Reply

  • Steve Steve avatar

    Posted on Jun 13, 2006 (permalink)

    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

    Reply

  • Dan Avni avatar

    Posted on Jun 14, 2006 (permalink)

    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

    Reply

  • JohnC avatar

    Posted on Sep 18, 2006 (permalink)

    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

    Reply

Back to Top

Skip Navigation LinksHome / Community & Support / Code Library / ASP.NET AJAX > General and Integration Projects > Page-level property to detect an Ajax callback