This is a migrated thread and some comments may be shown as answers.

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

1 Answer 95 Views
Ajax
This is a migrated thread and some comments may be shown as answers.
G S S
Top achievements
Rank 1
G S S asked on 31 Dec 2009, 01:45 AM
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







1 Answer, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 31 Dec 2009, 07:48 AM
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.
Tags
Ajax
Asked by
G S S
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Share this question
or