RadTreeView bug or RadPane feature?

1 posts, 0 answers
  1. alex lexx
    alex lexx avatar
    5 posts
    Member since:
    May 2010

    Posted 09 Feb 2011 Link to this post

    Please check this example...
    Then RadPane with ID = "catalogsPane" has EnableViewState is false, when on postback (expand tree node) all nodes will be removed, event OnNodeExpand will not be fired.

    full source code:

    <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm3.aspx.cs" Inherits="WebDesigner.WebForm3" %>
     
    <%@ Register Assembly="Telerik.Web.UI" Namespace="Telerik.Web.UI" TagPrefix="telerik" %>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <head runat="server">
      <title></title>
    </head>
    <body>
      <form id="form1" runat="server">
      <telerik:RadScriptManager ID="RadScriptManager" runat="server">
      </telerik:RadScriptManager>
      <telerik:RadAjaxManager ID="AjaxManager" runat="server" DefaultLoadingPanelID="AjaxLoadingPanel" EnableViewState="false">
      </telerik:RadAjaxManager>
      <telerik:RadAjaxLoadingPanel ID="AjaxLoadingPanel" Skin="Windows7" EnableViewState="false" runat="server">
      </telerik:RadAjaxLoadingPanel>
      <telerik:RadSplitter ID="viewSplitter" BorderStyle="None" PanesBorderSize="0" runat="server" Skin="Windows7">
        <telerik:RadPane runat="Server" ID="catalogsPane" Width="240px" MinWidth="100" EnableViewState="false">
          <telerik:RadTabStrip ID="RadTabStrip1" runat="server" SelectedIndex="1" MultiPageID="RadMultiPage1">
            <Tabs>
              <telerik:RadTab runat="server" Text="Tree" Selected="True">
              </telerik:RadTab>
            </Tabs>
          </telerik:RadTabStrip>
          <telerik:RadMultiPage ID="RadMultiPage1" runat="server">
            <telerik:RadPageView ID="RadPageView1" Selected="true" runat="server">
              <div runat="server" id="container">
                <div>tree:</div>
                <telerik:RadTreeView runat="server" ID="treeControl2" OnNodeExpand="CatalogTree_ExpandNode" OnLoad="CatalogTree_Load" NodeClick="CatalogTree_NodeClick">
                </telerik:RadTreeView>
              </div>
            </telerik:RadPageView>
          </telerik:RadMultiPage>
        </telerik:RadPane>
      </telerik:RadSplitter>
      <div runat="server" id="Div1">
      </div>
      </form>
    </body>
    </html>
    using System;
    using System.Collections.Generic;
    using System.Globalization;
    using System.Web.UI;
    using Telerik.Web.UI;
     
    namespace WebDesigner
    {
        public partial class WebForm3 : Page
        {
            private readonly List<SiteDataItem> _siteData = new List<SiteDataItem>();
     
            protected override void OnInit(EventArgs e)
            {
                InitSiteData();
                container.Controls.Add(treeControl2);
            }
     
            protected override void OnLoad(EventArgs e)
            {
                base.OnLoad(e);
                AjaxManager.AjaxSettings.AddAjaxSetting(treeControl2, treeControl2, AjaxLoadingPanel);
            }
     
            private static RadTreeNode CreateTreeNode(SiteDataItem item)
            {
                return new RadTreeNode
                {
                    Text = item.Text,
                    Value = item.ID.ToString(CultureInfo.InvariantCulture),
                    ExpandMode = TreeNodeExpandMode.ServerSide
                };
            }
     
            private void LoadNodes(IRadTreeNodeContainer treeControl, IRadTreeNodeContainer root, int? parentIdent)
            {
                var controlNodes = root == null ? treeControl.Nodes : root.Nodes;
                foreach (var item in this._siteData)
                {
                    if (parentIdent == item.ParentID)
                    {
                        var nodeControl = CreateTreeNode(item);
                        controlNodes.Add(nodeControl);
                    }
                }
            }
     
            protected void CatalogTree_NodeClick(object sender, RadTreeNodeEventArgs e)
            {
                throw new NotImplementedException();
            }
     
            protected void CatalogTree_Load(object sender, EventArgs e)
            {
                // make root nodes
                if (!Page.IsPostBack)
                {
                    var treeControl = sender as RadTreeView;
                    if (treeControl != null)
                    {
                        LoadNodes(treeControl, null, null);
                    }
                }
            }
     
            protected void CatalogTree_ExpandNode(object sender, RadTreeNodeEventArgs e)
            {
                if (e.Node.Nodes.Count == 0)
                {
                    LoadNodes(sender as IRadTreeNodeContainer, e.Node, Int32.Parse(e.Node.Value));
                }
            }
     
            private void InitSiteData()
            {
                this._siteData.Add(new SiteDataItem(1, null, "Products"));
                this._siteData.Add(new SiteDataItem(2, 1, "RadControls for ASP.NET Ajax"));
                this._siteData.Add(new SiteDataItem(3, 1, "RadControls for Silverlight"));
                this._siteData.Add(new SiteDataItem(4, 2, "RadGrid"));
                this._siteData.Add(new SiteDataItem(5, 2, "RadScheduler"));
                this._siteData.Add(new SiteDataItem(6, 2, "RadEditor"));
                this._siteData.Add(new SiteDataItem(7, 3, "RadGrid"));
                this._siteData.Add(new SiteDataItem(8, 3, "RadMenu"));
                this._siteData.Add(new SiteDataItem(9, 3, "RadEditor"));
            }
        }
     
        #region Support
     
        internal class SiteDataItem
        {
            private string _text;
            private int _id;
            private int? _parentId;
     
            public string Text
            {
                get { return _text; }
                set { _text = value; }
            }
     
            public int ID
            {
                get { return _id; }
                set { _id = value; }
            }
     
            public int? ParentID
            {
                get { return _parentId; }
                set { _parentId = value; }
            }
             
            public SiteDataItem(int id, int? parentId, string text)
            {
                _id = id;
                _parentId = parentId;
                _text = text;
            }
        }
     
        #endregion
    }
Back to Top