Header Context Menu with nested DetailTables causes StackOverflowException

3 posts, 0 answers
  1. Théophile
    Théophile avatar
    2 posts
    Member since:
    May 2016

    Posted 20 May Link to this post

    Hello,

    I recently started to work on an old ASP.Net project and one of the first action I was asked to perform was to update Telerik version (from Q3 2012 to the last one).

    The migration went almost well, but I have a problem in some specific situations : on every RadGrid with nested DetailTables, enable both HeaderContextMenu and HeaderContextFilterMenu causes a stack overflow exception during page loading.

     

    Here is an example :

    <telerik:RadGrid ID="RGPhase" runat="server" OnNeedDataSource="RGPhase_NeedDataSource" OnDetailTableDataBind="RGPhase_DetailTableDataBind" GridLines="None" PageSize="500" AutoGenerateColumns="false" Culture="fr-FR"
                        EnableHeaderContextMenu="true" EnableHeaderContextFilterMenu="false" AllowFilteringByColumn="true" AllowAutomaticInserts="True" AllowAutomaticUpdates="False" AllowAutomaticDeletes="False"
                        AllowPaging="True" AllowSorting="True" ShowFooter="True" OnEditCommand="RGPhase_EditCommand" OnCancelCommand="RGPhase_CancelCommand" OnUpdateCommand="RGPhase_UpdateCommand" OnDeleteCommand="RGPhase_DeleteCommand">
                        <MasterTableView DataKeyNames="IdPhaseInAffaire" IsFilterItemExpanded="false" CommandItemSettings-ShowRefreshButton="false" ShowGroupFooter="true" CommandItemDisplay="Top" CommandItemSettings-ShowAddNewRecordButton="false">
                            <NoRecordsTemplate>
                                Aucune phase
                            </NoRecordsTemplate>
                            <DetailTables>
                                <telerik:GridTableView GridLines="None" PageSize="500" AutoGenerateColumns="false" EnableHeaderContextMenu="false" EnableHeaderContextFilterMenu="false"
                                    AllowFilteringByColumn="true" DataKeyNames="IdPhaseInAffaire" AllowAutomaticInserts="false" AllowAutomaticUpdates="True" AllowAutomaticDeletes="false"
                                    AllowPaging="True" AllowSorting="True" ShowFooter="true" CommandItemStyle-CssClass="DontShow" CommandItemSettings-ShowRefreshButton="false" IsFilterItemExpanded="false"
                                    ShowGroupFooter="true" CommandItemDisplay="Top" CommandItemSettings-ShowAddNewRecordButton="false">
                                    <DetailTables>
                                        <telerik:GridTableView GridLines="None" PageSize="500" AutoGenerateColumns="false" EnableHeaderContextMenu="false" EnableHeaderContextFilterMenu="false"
                                            AllowFilteringByColumn="true" DataKeyNames="IdPhaseInAffaire" AllowAutomaticInserts="True" AllowAutomaticUpdates="True" AllowAutomaticDeletes="True" AllowPaging="True" AllowSorting="True"
                                            ShowFooter="true" CommandItemSettings-ShowRefreshButton="false" CommandItemStyle-CssClass="DontShow" IsFilterItemExpanded="false" ShowGroupFooter="true" CommandItemDisplay="Top" CommandItemSettings-ShowAddNewRecordButton="false">

     

    And the code behind associated : 

    protected void RGPhase_NeedDataSource(object sender, GridNeedDataSourceEventArgs e)
            {
                DataLoadOptions dlo = new DataLoadOptions();
                dlo.LoadWith<PhaseInAffaire>(p => p.Phase);
     
                RGPhase.DataSource = BLLPhase.GetAffairePhaseOnly(MyCompleteAffaire.IdAffaire, dlo);
            }
     
    protected void RGPhase_DetailTableDataBind(object sender, GridDetailTableDataBindEventArgs e)
            {
     
                var idPhaseInAffaire = (int)e.DetailTableView.ParentItem.GetDataKeyValue("IdPhaseInAffaire");
     
                var pia = MyCompleteAffaire.PhaseInAffaire.Where(c => c.IdParent == idPhaseInAffaire).ToList();
     
                e.DetailTableView.DataSource = pia;
     
            }

     

    When I set either "EnableHeaderContextMenu" or "EnableHeaderContextFilterMenu" to false, I have no problem loading the page.

     

    Apparently the server is stuck in a recursive call of this method : Telerik.Web.UI.GridHeaderContextMenu.GridContextFilterTemplate.CheckForSpecialColumns(Telerik.Web.UI.GridTableView currentTableView).

     

    Any help would be appreciated,

    Thanks

  2. Théophile
    Théophile avatar
    2 posts
    Member since:
    May 2016

    Posted 24 May Link to this post

    I figured it out after decompiling the Telerik.Web.UI dll. There is a bug in the "GridHeaderContextMenu.GridContextFilterTemplate.CheckForSpecialColumns" method :

    if (currentTableView.HasDetailTables)
    {
      foreach (GridTableView currentTableView1 in this.tableView.DetailTables)
        flag |= this.CheckForSpecialColumns(currentTableView1);
    }

    The foreach loop should be applied to the "currentTableView.DetailTables" collection, not the "this.tableView.DetailTables" or else the recursive call always has the root tableView children as a parameter, hence the Stack Overflow Exception if there are more than one detailTables level.

  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Konstantin Dikov
    Admin
    Konstantin Dikov avatar
    1803 posts

    Posted 24 May Link to this post

    Hi,

    We received another report for StackOverflowException from the CheckForSpecialColumns method and we are going to change the search to breath-first search and list, which should eliminate eliminate the chance to get stack overflow exception. 

    Please excuse us for any inconvenience caused by this.


    Regards,
    Konstantin Dikov
    Telerik
    Do you need help with upgrading your ASP.NET AJAX, WPF or WinForms projects? Check the Telerik API Analyzer and share your thoughts.
Back to Top