RadTreeView with ServerSideCallback not keeping extended RadTreeNode class

4 posts, 0 answers
  1. Matthew
    Matthew avatar
    6 posts
    Member since:
    Aug 2013

    Posted 11 Dec 2015 Link to this post

    Hi,

    I have a situation where I need to create a tree consisting of the following entities:

    Organization Entity

       ---> Organization Account

            --> Organization Account Record

     Organization Entities can have sub-Organization entities, Accounts can have sub-Accounts and records can have sub-records.

    As such I want to have different icons for the entity types, Different expand and click functionality based on the types and different context menu's for each type.

    I have created custom "RadTreeNode" classes in the following way:

        public class OrgNode: RadTreeNode
        {

            public OrgNode()
            {
                this.ExpandMode = TreeNodeExpandMode.ServerSideCallBack;
                this.ImageUrl = "../Images/image01.png";
            }
        }

        public class OrgAccountNode: RadTreeNode
        {
            public OrgAccountNode()
            {
                this.ExpandMode = TreeNodeExpandMode.ServerSideCallBack;
                this.ImageUrl = "../Images/image02.png";
            }
        }

        public class OrgAccountRecordNode: RadTreeNode
        {
            public OrgAccountRecordNode()
            {
                this.ExpandMode = TreeNodeExpandMode.ServerSideCallBack;
                this.ImageUrl = "../Images/image03.png";
            }
        }

    My problem exists when I use the "TreeView_NodeExpanded" method, because (as mentioned above) I want to do different things based on what type of node is expanded...

    Using the following statements:

    e.Node.GetType() 

    returns correctly for the top node (OrgNode - the only node on the page not created using the serversidecallback) but only returns "RadTreeNode" as the type for all other nodes which I have added using ServerSideCallback even though the nodes added are showing the correct images and text.

    Has anyone got any thoughts on this?

  2. Peter Filipov
    Admin
    Peter Filipov avatar
    1028 posts

    Posted 16 Dec 2015 Link to this post

    Hi Matthew,

    Please setup a runnable а sample and send it back for a local test. To determine from where the problem comes we need to debug your code. 

    Regards,
    Peter Filipov
    Telerik
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Matthew
    Matthew avatar
    6 posts
    Member since:
    Aug 2013

    Posted 17 Dec 2015 in reply to Peter Filipov Link to this post

    Hi Peter,

    Images are attached to this post.

    I am using telerik for asp.net version 2014.3.1209.45

    Please see below for code:

    /* ********************** Default.aspx ************************** */

    <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="Default" %>

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

    <html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
        <title></title>
        <telerik:RadStyleSheetManager id="RadStyleSheetManager1" runat="server" />
    </head>
    <body>
        <form id="form1" runat="server">
        <telerik:RadScriptManager ID="RadScriptManager1" runat="server">
            <Scripts>
                <asp:ScriptReference Assembly="Telerik.Web.UI" Name="Telerik.Web.UI.Common.Core.js" />
                <asp:ScriptReference Assembly="Telerik.Web.UI" Name="Telerik.Web.UI.Common.jQuery.js" />
                <asp:ScriptReference Assembly="Telerik.Web.UI" Name="Telerik.Web.UI.Common.jQueryInclude.js" />
            </Scripts>
        </telerik:RadScriptManager>
        <script type="text/javascript">
            //Put your JavaScript code here.
        </script>
        <telerik:RadAjaxManager ID="RadAjaxManager1" runat="server">
        </telerik:RadAjaxManager>
        <div>
            <telerik:RadTreeView ID="RadTreeView1" runat="server" OnNodeExpand="RadTreeView1_NodeExpand" Width="400px" Height="600px" Skin="MetroTouch"></telerik:RadTreeView>
        </div>
        </form>
    </body>
    </html>

    /* ***************************** End of Default.aspx *********************** */

    /* ***************************** Default.aspx.cs *************************** */

    using System;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.WebControls;

    using System.Data;
    using System.Configuration;
    using System.Web.Security;
    using System.Web.UI.WebControls.WebParts;
    using System.Web.UI.HtmlControls;
    using Telerik.Web.UI;
    using CommonTreeFunctions;

    public partial class Default : System.Web.UI.Page 
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            BPTreeFunctions.BPPhantomOrgNode topnode = new BPTreeFunctions.BPPhantomOrgNode();
            topnode.Text = "Organization Consolidated";
            RadTreeView1.Nodes.Add(topnode);
        }

        protected void RadTreeView1_NodeExpand(object sender, RadTreeNodeEventArgs e)
        {
            if (e.Node.Nodes.Count > 0)
                e.Node.Nodes.Clear();

            if(e.Node.GetType() == typeof(BPTreeFunctions.BPPhantomOrgNode))
            {
                BPTreeFunctions.BPOrgNode org1 = new BPTreeFunctions.BPOrgNode();
                org1.Text = "First Org";
                BPTreeFunctions.BPOrgNode org2 = new BPTreeFunctions.BPOrgNode();
                org2.Text = "Second Org";
                BPTreeFunctions.BPOrgNode org3 = new BPTreeFunctions.BPOrgNode();
                org3.Text = "Third Org";

                e.Node.Nodes.Add(org1);
                e.Node.Nodes.Add(org2);
                e.Node.Nodes.Add(org3);
            }

            if (e.Node.GetType() == typeof(BPTreeFunctions.BPOrgNode))
            {

                BPTreeFunctions.BPOrgAccountNode acc1 = new BPTreeFunctions.BPOrgAccountNode();
                acc1.Text = "First Account";
                BPTreeFunctions.BPOrgAccountNode acc2 = new BPTreeFunctions.BPOrgAccountNode();
                acc2.Text = "Second Account";
                BPTreeFunctions.BPOrgAccountNode acc3 = new BPTreeFunctions.BPOrgAccountNode();
                acc3.Text = "Third Account";

                BPTreeFunctions.BPOrgNode org4 = new BPTreeFunctions.BPOrgNode();
                org4.Text = "Sub Org";

                e.Node.Nodes.Add(acc1);
                e.Node.Nodes.Add(acc2);
                e.Node.Nodes.Add(acc3);
                e.Node.Nodes.Add(org4);
            }
        }
    }

    /* ***************************** End of Default.aspx.cs *********************** */

     /* **************************** BPTreeFunctions.cs ************************* */

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using Telerik.Web.UI;

    namespace CommonTreeFunctions
    {
        public class BPTreeFunctions
        {

            public delegate void BFARSTreeNodeClickEventHandler(object sender, RadTreeNodeEventArgs e);

            public class BPPhantomOrgNode : RadTreeNode
            {
                public BPPhantomOrgNode()
                {
                    this.ImageUrl = "~/Images/PhantomOrg_.png";
                    this.ExpandMode = TreeNodeExpandMode.ServerSideCallBack;
                }
            }

            public class BPOrgNode : RadTreeNode
            {
                public BPOrgNode()
                {
                    this.ImageUrl = "~/Images/Org.png";
                    this.ExpandMode = TreeNodeExpandMode.ServerSideCallBack;
                }
            }

            public class BPOrgAccountNode : RadTreeNode
            {
                public BPOrgAccountNode()
                {
                    this.ImageUrl = "~/Images/OrgAccount.png";
                    this.ExpandMode = TreeNodeExpandMode.ServerSideCallBack;
                }
            }

            public class BPControlledOrgAccountNode : RadTreeNode
            {
                public BPControlledOrgAccountNode()
                {
                    this.ImageUrl = "~/Images/ControlledOrgAccount.png";
                    this.ExpandMode = TreeNodeExpandMode.ServerSideCallBack;
                }
            }

            public class BPRecordNode : RadTreeNode
            {
                public BPRecordNode()
                {
                    this.ImageUrl = "~/Images/Record.png";
                    this.ExpandMode = TreeNodeExpandMode.ServerSideCallBack;
                }
            }
        }
    }

    /* ******************************* End of BPTreeFunctions.cs ****************************** */

  5. Peter Filipov
    Admin
    Peter Filipov avatar
    1028 posts

    Posted 22 Dec 2015 Link to this post

    Hi Matthew,

    I was able to reproduce the issue. It seems that there is a problem with different types and the callback mechanism of the Asp.Net. My suggestion is to set different expand mode of the nodes - ServerSide and place the control into RadAjaxPanel or RadAjaxManager. Another approach that could be used is to set attributes to the nodes which will indicate their type. I am sending you a sample for a reference.

    Regards,
    Peter Filipov
    Telerik
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
Back to Top