Checked is always false on TreePanel submit nodes.

Page 1 of 2 12 LastLast
  1. #1

    Checked is always false on TreePanel submit nodes.

    I have a simplified example and it seems that "Checked" for every node, including root is false. After some searching, I added this to my click listener's handler:
    App.tpPermissions.updateCheckSelection();
    Default.aspx:
    <%@ Page Title="" Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs"
        Inherits="Ext.NET_2_Site.Default" %>
    
    <%@ Register Assembly="Ext.Net" Namespace="Ext.Net" TagPrefix="ext" %>
    <!DOCTYPE html>
    <html>
    <head id="Head1" runat="server">
        <title>Dynamic Nodes - Tree Panel</title>
    </head>
    <body>
        <ext:ResourceManager ID="ResourceManager1" runat="server" IDMode="Explicit" />
        <ext:TreePanel ID="tpPermissions" runat="server" RootVisible="true" AutoScroll="true"
            Title="Permissions" Width="500" UseArrows="true" Icon="Link" Animate="false"
            OnSubmit="SubmitNodes" Height="500">
            <Store>
                <ext:TreeStore ID="TreeStore1" runat="server">
                    <Proxy>
                        <ext:AjaxProxy Url="TreePanelHandler.ashx" />
                    </Proxy>
                </ext:TreeStore>
            </Store>
            <Root>
                <ext:Node NodeID="root" Text="Root" Checked="false" />
            </Root>
            <BottomBar>
                <ext:Toolbar ID="Toolbar1" runat="server">
                    <Items>
                        <ext:Button ID="btnSave" runat="server" Text="Save" Icon="Disk">
                            <Listeners>
                                <Click Handler="App.tpPermissions.updateCheckSelection();#{tpPermissions}.submitNodes();" />
                            </Listeners>
                        </ext:Button>
                    </Items>
                </ext:Toolbar>
            </BottomBar>
        </ext:TreePanel>
    </body>
    </html>
    Default.aspx.cs:
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using Ext.Net;
    
    namespace Ext.NET_2_Site
    {
        public partial class Default : System.Web.UI.Page
        {
            protected void Page_Load(object sender, EventArgs e)
            {
                  
            }
    
            protected void SubmitNodes(object sender, SubmitEventArgs e)
            {
                var chk2 = tpPermissions.CheckedNodes;
    
                var nodes = e.RootNode.Children;
                var chk = nodes.Where(n => n.Checked);
                //chk2 is null, nodes has everything but checked is always false, and chk is empty
            }
    
        }
    }
    TreePanelHandler.ashx.cs
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Web.Services;
    using Ext.Net;
    
    namespace Ext.NET_2_Site
    {
        /// <summary>
        /// Summary description for TreePanelHandler
        /// </summary>
        [WebService(Namespace = "http://tempuri.org/")]
        [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
        public class TreePanelHandler : IHttpHandler
        {
            public HttpContext Context { get; set; }
            
            public void ProcessRequest(HttpContext context)
            {
                Context = context;
                context.Response.ContentType = "text/plain";
    
                string nodeId = context.Request["node"];
    
                if (string.IsNullOrEmpty(nodeId))
                {
                    NodeCollection nodes = new NodeCollection(false);
    
                    context.Response.Write(nodes.ToJson());
                    context.Response.End();
                }
                else if (nodeId == "root")
                {
                    NodeCollection nodes = new NodeCollection(false);
    
                    Ext.Net.Node sn = new Ext.Net.Node();
                    sn.Text = "Site";
                    sn.Icon = Icon.WorldLink;
                    sn.NodeID = "1";
    
                    Ext.Net.Node an = new Ext.Net.Node();
                    an.Text = "Application";
                    an.Icon = Icon.ApplicationLink;
                    an.NodeID ="2";
    
                    Ext.Net.Node pn = new Ext.Net.Node();
                    pn.Text = "Permission";
                    pn.Icon = Icon.Link;
                    pn.NodeID = "3";
                    pn.Leaf = true;
                    pn.Checked = false;
                    an.Children.Add(pn);
                    sn.Children.Add(an);
    
                    nodes.Add(sn);
    
                    context.Response.Write(nodes.ToJson());
                    context.Response.End();
                }
                else
                {
                    NodeCollection nodes = new NodeCollection(false);
    
                    context.Response.Write(nodes.ToJson());
                    context.Response.End();
                }
      
            }
    
            public bool IsReusable
            {
                get
                {
                    return false;
                }
            }
        }
    }
    Last edited by Uziel; Sep 26, 2012 at 7:09 PM.
  2. #2
    You have no ASP.NET html form therefore checked nodes are not submitted
  3. #3
    Quote Originally Posted by Vladimir View Post
    You have no ASP.NET html form therefore checked nodes are not submitted
    Thanks for the quick reply.
    I added a form tag and still aren't getting any checked nodes via e.RootNode.
    tpPermissions.CheckedNodes has the checked nodes, but I need the entire tree and whether each node is checked or not. The end usage is a permissions updating control (i.e., if the user has a permission and its unchecked, remove it in the db; if they don't have it and its checked, add it in the db).

    <%@ Page Title="" Language="C#" AutoEventWireup="true" CodeBehind="TreePanel_DynamicNodes.aspx.cs"
        Inherits="Ext.NET_2_Site.TreePanel_DynamicNodes" %>
    
    <%@ Register Assembly="Ext.Net" Namespace="Ext.Net" TagPrefix="ext" %>
    <!DOCTYPE html>
    <html>
    <head id="Head1" runat="server">
        <title>Dynamic Nodes - Tree Panel</title>
    </head>
    <body>
        <form runat="server">
        <ext:ResourceManager ID="ResourceManager1" runat="server" IDMode="Explicit" />
        <ext:Button runat="server" ID="btnUserSearch" Text="Search">
            <DirectEvents>
                <Click OnEvent="UserSearch" />
            </DirectEvents>
        </ext:Button>
        <br />
        <ext:TreePanel ID="tpPermissions" runat="server" RootVisible="true" AutoScroll="true"
            Title="Permissions" Width="500" UseArrows="true" Icon="Link" Animate="false"
            OnSubmit="SubmitNodes" Height="500">
            <Store>
                <ext:TreeStore ID="TreeStore1" runat="server">
                    <Proxy>
                        <ext:AjaxProxy Url="TreePanelHandler.ashx" />
                    </Proxy>
                </ext:TreeStore>
            </Store>
            <Root>
                <ext:Node NodeID="root" Text="Root" Checked="false" />
            </Root>
            <BottomBar>
                <ext:Toolbar ID="Toolbar1" runat="server">
                    <Items>
                        <ext:Button ID="btnSave" runat="server" Text="Save" Icon="Disk">
                            <Listeners>
                                <Click Handler="App.tpPermissions.updateCheckSelection();#{tpPermissions}.submitNodes();" />
                            </Listeners>
                        </ext:Button>
                    </Items>
                </ext:Toolbar>
            </BottomBar>
        </ext:TreePanel>
        </form>
    </body>
    </html>
    Last edited by Uziel; Sep 27, 2012 at 12:56 PM. Reason: Added clarity
  4. #4
    I cannot reproduce the issue, checked nodes are not null for me
  5. #5
    Quote Originally Posted by Vladimir View Post
    I cannot reproduce the issue, checked nodes are not null for me
    tpPermissions.CheckedNodes populates the check/unchecked with the form tag, however I need to see checked/unchecked in e.RootNode.Children.
     
    protected void SubmitNodes(object sender, SubmitEventArgs e)
            {
                var nodes = e.RootNode.Children;
            }
    Are you able to view the Checked of e.RootNode.Children and see anything other than false? I'm using 2.0.0.0. I have a friend that has a pro license and he ran the same code with 2.1.0.25802. For him, e.RootNode correctly shows Checked as true when its checked, but e.RootNode.Children's Checked throws the exception "{"Object reference not set to an instance of an object."} for every single child of root.

    e.RootNode works correctly for this purpose in 1.5 and I'm using it in production code, but for a new project we are opting for 2.0 and converting some of our controls.
  6. #6
    First, Nodes are not recreated on the server side therefore if you do not repopulate Root.Children then that collection will be null
    Also TreePanel doesn't update Checked property of nodes, you have to use CheckedNodes collection of a tree to get nodes with Checked=true
  7. #7
    I tried the equivalent code in 1.5 and it doesn't have "Checked" when using a handler. It does, however, have "Checked" when using another load method.
    When I switch the 2.0 code to use another load method for the tree such as PageMethod, it still doesn't have the correct values for "Checked".

    However, my friend tried the 2.1 dll and it DOES correctly have the checked as true. For non checked nodes, it throws the exception "{"Object reference not set to an instance of an object."}.

    2.1 in debug:
    Click image for larger version. 

Name:	2.1checked.png 
Views:	137 
Size:	51.4 KB 
ID:	4842
    So there is a code difference in this regard between 1.5, 2.0, and 2.1.
    I have 1.5 doing exactly what I need, 2.0 doesn't work and 2.1 half works.

    Could you please try this in both 2.0 and 2.1 to see? Using this code:

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using Ext.Net;
    
    namespace Ext.NET_2_Site
    {
        public partial class Default : System.Web.UI.Page
        {
            protected void Page_Load(object sender, EventArgs e)
            {
    
            }
    
            protected void SubmitNodes(object sender, SubmitEventArgs e)
            {
                var nodes = e.RootNode.Children;
                var chk = nodes.Where(n => n.Checked);
            }
    
            protected void NodeLoad(object sender, NodeLoadEventArgs e)
            {
                if (!string.IsNullOrEmpty(e.NodeID))
                {
                    Ext.Net.Node sn = new Ext.Net.Node();
                    sn.Text = "Site";
                    sn.Icon = Icon.WorldLink;
                    sn.NodeID = "1";
    
                    Ext.Net.Node an = new Ext.Net.Node();
                    an.Text = "Application";
                    an.Icon = Icon.ApplicationLink;
                    an.NodeID = "2";
    
                    Ext.Net.Node pn = new Ext.Net.Node();
                    pn.Text = "Permission";
                    pn.Icon = Icon.Link;
                    pn.NodeID = "3";
                    pn.Leaf = true;
                    pn.Checked = false;
                    an.Children.Add(pn);
                    sn.Children.Add(an);
    
                    e.Nodes.Add(sn);
                }
            }
        }
    }
    %@ Page Title="" Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs"
        Inherits="Ext.NET_2_Site.Default" %>
    
    <%@ Register Assembly="Ext.Net" Namespace="Ext.Net" TagPrefix="ext" %>
    <!DOCTYPE html>
    <html>
    <head id="Head1" runat="server">
        <title>Dynamic Nodes - Tree Panel</title>
    </head>
    <body>
        <form runat="server">
        <ext:ResourceManager ID="ResourceManager1" runat="server" IDMode="Explicit" />
        <ext:TreePanel ID="tpPermissions" runat="server" RootVisible="true" AutoScroll="true"
            Title="Permissions" Width="500" UseArrows="true" Icon="Link" Animate="false"
            Height="500" OnSubmit="SubmitNodes">
            <Store>
                <ext:TreeStore ID="TreeStore1" runat="server" OnReadData="NodeLoad">
                    <Proxy>
                        <ext:PageProxy />
                    </Proxy>
                </ext:TreeStore>
            </Store>
            <Root>
                <ext:Node NodeID="root" Text="Root" />
            </Root>
            <BottomBar>
                <ext:Toolbar ID="Toolbar1" runat="server">
                    <Items>
                        <ext:Button ID="btnSave" runat="server" Text="Save" Icon="Disk">
                            <Listeners>
                                <Click Handler="#{tpPermissions}.submitNodes();" />
                            </Listeners>
                        </ext:Button>
                    </Items>
                </ext:Toolbar>
            </BottomBar>
        </ext:TreePanel>
        </form>
    </body>
    </html>
  8. #8
    Please read my previous post again
    You have to use CheckedNodes collection of TreePanel to get checked nodes
    You don't need to submit nodes to get checked nodes
  9. #9
    May be I misunderstood you
    Do you want to say that if submitted node has no checkbox in the tree then its Checked property raises an exception?
  10. #10
    Quote Originally Posted by Vladimir View Post
    Please read my previous post again
    You have to use CheckedNodes collection of TreePanel to get checked nodes
    You don't need to submit nodes to get checked nodes
    Quote Originally Posted by Vladimir View Post
    May be I misunderstood you
    Do you want to say that if submitted node has no checkbox in the tree then its Checked property raises an exception?
    Sorry if I wasn't clear.
    I know that CheckedNodes will give me the checked nodes. For my current purposes, I need the tree as a collection so I can have a list of checked nodes AND unchecked nodes.

    If I use submitNodes() and get the nodes collection via e.RootNode.Chilren (SubmitEventArgs e), I get exactly what I need in ext.net 1.5. I don't get this in 2.0.0.0. I get it in 2.1 but non checked nodes throw an exception.

    For example:
    If my tree is
    Root/Site/Application/Permission, with Permission being checkable

    And I use submitNodes() and handle it via:
    protected void SubmitNodes(object sender, SubmitEventArgs e)
            {
                var nodes = e.RootNode.Children;
            }
    When I check the permissions checkbox and submit the nodes, I get the following results:

    ext 1.5
    Root: checked false
    -Site: checked false
    --Application: checked false
    ---Permission: checked true
    ext 2.0
    Root: checked false
    -Site: checked false
    --Application: checked false
    ---Permission: checked false
    ext 2.1
    Root: checked Object reference not set to an instance of an object
    -Site: checked Object reference not set to an instance of an object
    --Application: checked Object reference not set to an instance of an object
    ---Permission: checked true
    So to reiterate, this already works in 1.5, is seemingly broken in 2.0 and is halfway working in 2.1.
    Last edited by Uziel; Sep 27, 2012 at 9:47 PM.
Page 1 of 2 12 LastLast

Similar Threads

  1. Replies: 1
    Last Post: May 27, 2011, 11:39 AM
  2. [CLOSED] [1.0] TreePanel Checked
    By Timothy in forum 1.x Legacy Premium Help
    Replies: 3
    Last Post: Jan 09, 2011, 5:02 PM
  3. Replies: 1
    Last Post: Aug 11, 2010, 7:32 PM
  4. Checked Nodes
    By fabiomarcos in forum 1.x Help
    Replies: 6
    Last Post: Jan 01, 2010, 12:29 PM
  5. TreePanel enumerate through checked nodes
    By PeterSam in forum 1.x Help
    Replies: 1
    Last Post: Feb 02, 2009, 5:25 PM

Tags for this Thread

Posting Permissions