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

    Hi,

    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"
                                                                                    <AjaxSettings> 
                                                                                        <telerik:AjaxSetting AjaxControlID="RadTreeView1"
                                                                                            <UpdatedControls> 
                                                                                                <telerik:AjaxUpdatedControl ControlID="RadTreeView1" /> 
                                                                                                        <telerik:AjaxUpdatedControl /> 
                                                                                                <telerik:AjaxUpdatedControl ControlID="RadGrid1" LoadingPanelID="RadAjaxLoadingPanel1" /> 
                                                                                                </UpdatedControls> 
                                                                                       </telerik:AjaxSetting> 
                                                                                 </AjaxSettings> 
                                                                                </telerik:RadAjaxManager> 


    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?


    Thanks







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

    Posted 31 Dec 2009 Link to this post

    Hello,

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

    CS:
     
    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 
                { 
                    Response.Write("RadMenu"); 
                } 
            } 
        } 
     
    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  
            else 
            { 
                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); 
                    } 
                    else 
                    { 
                        c = Page.FindControl(ctl); 
                    } 
                    if (c is System.Web.UI.WebControls.Button || c is System.Web.UI.WebControls.ImageButton) 
                    { 
                        control = c; 
                        break
                    } 
                } 
            } 
            return control.ID; 
        }   
    protected void RadMenu1_ItemClick(object sender, Telerik.Web.UI.RadMenuEventArgs e) 
        { 
            RadGrid1.Rebind(); 
        } 

    Thanks,
    Princy.
  3. UI for ASP.NET Ajax is Ready for VS 2017
Back to Top