Identifying whether RadGrid (in RadAjaxManager) or Page_Load calls NeedDataSource()

2 posts, 0 answers
  1. G S S
    G S S avatar
    85 posts
    Member since:
    Mar 2008

    Posted 30 Dec 2009 Link to this post


    I need to identify, when calling NeedDataSource() on my RADGrid, whether the action to invoke this is the RADMenu click (server-side click event handler for this control calls NeedDataSource()) or Page_Load, which calls likewise.

    My RADGrid is in a RADAjaxManager:

                                      <telerik:RadAjaxManager ID="AjaxManager1" runat="server" EnableHistory="True"
                                                                                        <telerik:AjaxSetting AjaxControlID="RadTreeView1"
                                                                                                <telerik:AjaxUpdatedControl ControlID="RadTreeView1" /> 
                                                                                                        <telerik:AjaxUpdatedControl /> 
                                                                                                <telerik:AjaxUpdatedControl ControlID="RadGrid1" LoadingPanelID="RadAjaxLoadingPanel1" /> 

    Thus, will the below work?

            RadMenu test = source as RadMenu; 

    So if this is null, RadMenu could not be invoking the event handler and thus it must be Page_Load. I am not soure if object source is like object sender, and if I should replace RadMenu with RadAjaxManager?


  2. Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 31 Dec 2009 Link to this post


    You can check for the control which invokes the postback using following code. I hope this will help.

    protected void RadGrid1_NeedDataSource(object source, Telerik.Web.UI.GridNeedDataSourceEventArgs e) 
            RadGrid1.MasterTableView.DataSource = GetDataTable("SELECT * FROM Customers"); 
            if (IsPostBack) 
                if (getPostBackControlName() == "RadMenu1"// Check for the control id which invokes the postback 
    private string getPostBackControlName() 
            Control control = null
            string ctrlname = Page.Request.Params["__EVENTTARGET"]; 
            if (ctrlname != null && ctrlname != String.Empty) 
                control = Page.FindControl(ctrlname); 
            // if __EVENTTARGET is null, the control is a button type and we need to  
            // iterate over the form collection to find it  
                string ctrlStr = String.Empty; 
                Control c = null
                foreach (string ctl in Page.Request.Form) 
                    if (ctl.EndsWith(".x") || ctl.EndsWith(".y")) 
                        ctrlStr = ctl.Substring(0, ctl.Length - 2); 
                        c = Page.FindControl(ctrlStr); 
                        c = Page.FindControl(ctl); 
                    if (c is System.Web.UI.WebControls.Button || c is System.Web.UI.WebControls.ImageButton) 
                        control = c; 
            return control.ID; 
    protected void RadMenu1_ItemClick(object sender, Telerik.Web.UI.RadMenuEventArgs e) 

  3. DevCraft R3 2016 release webinar banner
Back to Top