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

RadGrid with RadContextMenu not working on "postback"

3 Answers 383 Views
Menu
This is a migrated thread and some comments may be shown as answers.
Brian
Top achievements
Rank 1
Brian asked on 04 Mar 2009, 03:38 PM
I have a radgrid that uses a rad context menu.  The rad grid itself is controlled through a rad ajax manager and it uses the automatic inserts, updates, and deletes.  When the page loads, the context menu works fine.  But if I insert a new record, edit a record, delete a record, sort the grid, or refresh the grid with the automatic refresh button, the context menu disappears and when I right click, I get the normal IE7 popup dialog.

Here's the code:

    <telerik:RadCodeBlock ID="rcb" runat="server" > 
    <script type="text/javascript" language="javascript" > 
        var rgFunding = null 
        var rcmFunding = null 
        var motype = null 
          
        function pageLoad() {  
            rgFunding = $find('<%= rgFunding.ClientID %>')  
            rcmFunding = $find('<%= rcmFunding.ClientID %>');  
            motype = $find('<%= motype.ClientID %>');  
        }  
        function fundingClientClicked(sender, args) {  
            var itemLabel = args.get_item().get_value();  
            switch (itemLabel) {  
                case "Select All":  
                    rgFunding.get_masterTableView().selectAllItems();  
                    break;  
                case "Clear All":  
                    rgFunding.get_masterTableView().clearSelectedItems();  
                    break;  
                case "Move":  
                    var selectedRows = rgFunding.get_masterTableView().get_selectedItems();  
                    for (i = 0; i < selectedRows.length; i++) {  
                        iID = selectedRows[i].getDataKeyValue("iID");  
                        bIsFlagselectedRows[i].getDataKeyValue("bIsFlag");  
                        PageMethods.MoveFunding(iID, bIsFlag == "True" ? false : true, Repaint, HandleError);  
                    }  
                    break;  
            }  
        }  
        function Repaint(results) {  
            location.reload(true);  
        }  
    </script> 
    </telerik:RadCodeBlock> 
    <telerik:RadAjaxManager ID="RadAjaxManager1" runat="server"   
        DefaultLoadingPanelID="RadAjaxLoadingPanel1">  
        <ajaxsettings> 
            <telerik:AjaxSetting AjaxControlID="rgFunding">  
                <updatedcontrols> 
                    <telerik:AjaxUpdatedControl ControlID="rgFunding" LoadingPanelID="RadAjaxLoadingPanel1" /> 
                </updatedcontrols> 
            </telerik:AjaxSetting> 
        </ajaxsettings> 
    </telerik:RadAjaxManager> 
    <telerik:RadAjaxLoadingPanel ID="RadAjaxLoadingPanel1" runat="server" Height="75px" 
        Width="75px" Transparency="25" > 
        <img alt="Loading..." src='<%= RadAjaxLoadingPanel.GetWebResourceUrl(Page, "Telerik.Web.UI.Skins.Default.Ajax.loading.gif") %>' 
            style="border: 0px;" /> 
    </telerik:RadAjaxLoadingPanel> 
    <telerik:RadContextMenu ID="rcmFunding" runat="server"   
        Skin="WebBlue" OnClientItemClicked="fundingClientClicked"   
        style="top: 213px; left: 317px" > 
        <Targets> 
            <telerik:ContextMenuControlTarget ControlID="rgFunding" /> 
        </Targets> 
        <CollapseAnimation Type="OutQuint" Duration="200"></CollapseAnimation> 
    </telerik:RadContextMenu> 
    <asp:Label ID="lblFundingHeader" runat="server" CssClass="HeaderTag" /> 
    <telerik:RadGrid ID="rgFunding" runat="server" Skin="WebBlue"   
        AutoGenerateColumns="False" GridLines="None" ShowFooter="True"   
        AllowSorting="True" AllowAutomaticInserts="true" AllowAutomaticUpdates="true"   
        AllowAutomaticDeletes="true" DataSourceID="ldsFunding"   
        AllowMultiRowEdit="true" oncustomaggregate="rgFunding_CustomAggregate"   
        OnDataBound="rgFunding_DataBound" Width="1000px"   
        onitemdeleted="rgFunding_ItemDeleted" oniteminserted="rgFunding_ItemInserted"   
        onitemupdated="rgFunding_ItemUpdated" AllowMultiRowSelection="True"   
        onitemcreated="rgFunding_ItemCreated" > 
        <ClientSettings> 
            <Selecting AllowRowSelect="true" /> 
            <Scrolling AllowScroll="true" UseStaticHeaders="true" ScrollHeight="200px" /> 
        </ClientSettings> 
        <HeaderContextMenu Skin="WebBlue">  
            <CollapseAnimation Type="OutQuint" Duration="200"></CollapseAnimation> 
        </HeaderContextMenu> 
        <MasterTableView DataSourceID="ldsFunding" CommandItemDisplay="Top" DataKeyNames="iID" ClientDataKeyNames="iID, bIsFlag" AutoGenerateColumns="false" EditMode="InPlace" > 
            <Columns> 
                <telerik:GridEditCommandColumn ButtonType="ImageButton" UniqueName="Edit" ItemStyle-Width="25px" > 
                    <ItemStyle CssClass="editbutton" /> 
                </telerik:GridEditCommandColumn> 
                <telerik:GridBoundColumn DataField="iID" HeaderText="ID" ReadOnly="true" SortExpression="iID" UniqueName="iID" Visible="False" /> 
                <telerik:GridDateTimeColumn DataField="dtSettlement" ItemStyle-Width="55px" HeaderText="Settlement" SortExpression="dtSettlement" UniqueName="dtSettlement" DataFormatString="{0:d}" /> 
                <telerik:GridDateTimeColumn DataField="dtMaturity" ItemStyle-Width="55px" HeaderText="Maturity" SortExpression="dtMaturity" UniqueName="dtMaturity" DataFormatString="{0:d}" /> 
                <telerik:GridNumericColumn DataField="curAmount" ItemStyle-Width="55px" HeaderText="Amount" SortExpression="curAmount" UniqueName="curAmount" DataFormatString="{0:N3}" Aggregate="Sum" /> 
                <telerik:GridBoundColumn DataField="iNoOfDays" ReadOnly="true" ItemStyle-Width="45px" HeaderText="# of<br />Days" SortExpression="iNoOfDays" UniqueName="iNoOfDays" DataFormatString="{0:0}" Aggregate="Custom" /> 
                <telerik:GridBoundColumn DataField="sSource" ItemStyle-Width="55px" HeaderText="Source" SortExpression="sSource" UniqueName="sSource" /> 
                <telerik:GridNumericColumn DataField="nCost" ItemStyle-Width="45px" HeaderText="Cost" SortExpression="nCost" UniqueName="nCost" DataFormatString="{0:N3}" Aggregate="Custom" /> 
                <telerik:GridButtonColumn ConfirmText="Delete this Funding?" ConfirmDialogType="RadWindow" ConfirmTitle="Delete" ButtonType="ImageButton" CommandName="Delete" Text="Delete" UniqueName="DeleteColumn">  
                    <ItemStyle HorizontalAlign="Center" CssClass="deletebutton" /> 
                </telerik:GridButtonColumn> 
            </Columns> 
        </MasterTableView> 
        <FilterMenu Skin="WebBlue">  
            <CollapseAnimation Type="OutQuint" Duration="200"></CollapseAnimation> 
        </FilterMenu> 
    </telerik:RadGrid> 
    <asp:LinqDataSource ID="ldsFunding" runat="server"   
        ContextTypeName="fhlb.debt.middletier.DAL.DebtDataContext" EnableInsert="true"   
        EnableDelete="true" EnableUpdate="true" TableName="Funding_Currents" 
        OnInserting="ldsFunding_Inserting" OnDeleting="ldsFunding_Deleting"   
        OnUpdating="ldsFunding_Updating" oninserted="ldsFunding_Inserted"   
        onupdated="ldsFunding_Updated" Where="bIsFlag == @ bIsFlag&amp;&amp; dtBOM == @dtBOM" > 
        <WhereParameters> 
            <asp:QueryStringParameter Name="bIsFlag" QueryStringField="Flag" DefaultValue="false" Type="Boolean" /> 
            <asp:QueryStringParameter Name="dtBOM" QueryStringField="BOM" Type="DateTime" /> 
        </WhereParameters> 
    </asp:LinqDataSource> 
    <telerik:RadWindowManager ID="RadWindowManager1" runat="server"   
        style="font-weight: 700">  
    </telerik:RadWindowManager> 
 
 
        protected void Page_Load(object sender, EventArgs e)  
        {  
            LoadFormElements();  
        }  
 
 
        private void LoadFormElements()  
        {             
            lblFundingHeader.Text = "Funding";  
            rcmFunding.Items.Clear();  
 
 
            RadMenuItem rmiMove = new RadMenuItem();  
            rmiMove.Text = "Move to " + (this.bIsFlag ? "Yes" : "No");  
            rmiMove.Value = "Move";  
              
            rmiMove.Attributes.Add("motype", (this.bIsFlag ? "Yes" : "No"));  
            rmiMove.PostBack = true;  
            RadMenuItem rmiSelectAll = new RadMenuItem();  
            rmiSelectAll.Text = "Select All";  
            rmiSelectAll.Value = "Select All";  
            RadMenuItem rmiClearAll = new RadMenuItem();  
            rmiClearAll.Text = "Clear All";  
            rmiClearAll.Value = "Clear All";  
            rcmFunding.Items.Add(rmiMove);  
            rcmFunding.Items.Add(rmiSelectAll);  
            rcmFunding.Items.Add(rmiClearAll);  
        }  
 
 
        [WebMethod]  
        public static void MoveFunding(string sID, Boolean bIsFlag)  
        {  
            Funding.MoveFunding(Convert.ToInt32(sID), bIsFlag);  
        }  
 

Now the first thing I tried to fix it was to define the radcontextmenu items in the aspx page, but that netted the same results.

Any ideas?

3 Answers, 1 is accepted

Sort by
0
Brian
Top achievements
Rank 1
answered on 04 Mar 2009, 06:43 PM
Okay, I have figured out what is causing my issue, the rad ajax manager.  When I remove it, my context menu shows up after I insert a record, edit a record, delete a record, sort, or refresh with the radgrid refresh button.  When I add it back in, after I do any of those things, the context menu disappears.

Any ideas?
0
Accepted
Veselin Vasilev
Telerik team
answered on 07 Mar 2009, 10:30 AM
Hello Brian,

You just need to add one more AjaxSetting - that RadGrid updates RadContextMenu as well. Here is a sample:

<telerik:RadAjaxManager ID="RadAjaxManager1" runat="server"
    <AjaxSettings> 
        <telerik:AjaxSetting AjaxControlID="RadGrid1"
            <UpdatedControls> 
                <telerik:AjaxUpdatedControl ControlID="RadGrid1"></telerik:AjaxUpdatedControl> 
                <telerik:AjaxUpdatedControl ControlID="RadContextMenu1"></telerik:AjaxUpdatedControl> 
            </UpdatedControls> 
        </telerik:AjaxSetting> 
    </AjaxSettings> 
</telerik:RadAjaxManager> 

I hope this helps.

Regards,
Veselin Vasilev
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
0
Brian
Top achievements
Rank 1
answered on 09 Mar 2009, 11:23 AM
Argh!  Duh!  Wow, that makes perfect sense.  Not sure how I didn't think of it.  Thank you so much.
Tags
Menu
Asked by
Brian
Top achievements
Rank 1
Answers by
Brian
Top achievements
Rank 1
Veselin Vasilev
Telerik team
Share this question
or