Home - Forums-.NET - FlyTreeView (ASP.NET) - Error on removing child node

FlyTreeView (ASP.NET)

Technical support and KB related to the FlyTreeView control

This forum related to following products: FlyTreeView for ASP.NET

Error on removing child node
Link Posted: 19-Mar-2009 00:48
Hi All

When removing a child node I get "Object reference not set to an instance of an object".
This error does not occur in my own code. Funny thing is that I can remove top level nodes without  a problem.

Here is the code that removes the node (this is the same code that removes top level nodes without error):
FlyTreeNode node = uxSkills.SelectedNode;
uxSkills.Nodes.Remove(node);

Stack trace:
[NullReferenceException: Object reference not set to an instance of an object.]
   NineRays.WebControls.FlyTreeNode.get_NodeType() +300
   NineRays.WebControls.FlyTreeNode.SetContentContainer(Boolean useDataBinding, Boolean useDataBindingSoft) +61
   NineRays.WebControls.FlyTreeNode.DataBindContentContainerRecursive() +69
   NineRays.WebControls.FlyTreeNode.DataBindContentContainerRecursive() +131
   NineRays.WebControls.FlyTreeView.SetContentContainersRecursive() +118
   NineRays.WebControls.FlyTreeView.OnPreRender(EventArgs e) +78
   System.Web.UI.Control.PreRenderRecursiveInternal() +80
   System.Web.UI.Control.PreRenderRecursiveInternal() +171
   System.Web.UI.Control.PreRenderRecursiveInternal() +171
   System.Web.UI.Control.PreRenderRecursiveInternal() +171
   System.Web.UI.Control.PreRenderRecursiveInternal() +171
   System.Web.UI.Control.PreRenderRecursiveInternal() +171
   System.Web.UI.Control.PreRenderRecursiveInternal() +171
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +842

Any help will be greatly appreciated.
Regards
Conrad Pienaar
Link Posted: 19-Mar-2009 07:40
Conrad,

Where from do you call uxSkills.Nodes.Remove(node) ?

I mean Page_Load, some event handler or anything else?
Link Posted: 19-Mar-2009 21:09
[quote="EvgenyT"]Conrad,

Where from do you call uxSkills.Nodes.Remove(node) ?

I mean Page_Load, some event handler or anything else?


Evgeny

I call it from the command event of a contextmenu:
protected void uxSkillsMenu_Command(object sender, FlyContextMenuCommandEventArgs e)
        {

            int skillID = Int32.Parse(uxSkills.FindByID(e.CommandArgument).Value);
            string dscr = uxSkills.FindByID(e.CommandArgument).Text;

            // CLEAR POPUP FORM
            uxHiddenSkillsetID.Value = "";
            uxHiddenSkillID.Value = "";
            uxDescription.Text = "";

            switch (e.CommandName)
            {
                case "Delete":
                    {
                        DeleteSkill(skillID);
                        break;
                    }
                case "Edit":
                    {
                        uxHiddenSkillID.Value = skillID.ToString();
                        uxDescription.Text = dscr;
                        ModalPopupExtender1.Show();
                        break;
                    }
            }
        }


And here is the actual code that performs the deletion:
        private void DeleteSkill(int skillID)
        {
            // DELETES A SKILL OR SKILLSET
            try
            {
                DALSkills dalSkills = new DALSkills();

                dalSkills.Delete(skillID);

                FlyTreeNode node = uxSkills.SelectedNode;

                uxSkills.Nodes.Remove(node);
            }
            catch (Exception E)
            {
                Session[Constants.SESSION_Error] = E.Message.ToString();
                Response.Redirect(Constants.ErrorPageURL);
            }
        }


Regards
Conrad
Link Posted: 20-Mar-2009 03:02
Just tried to reproduced using a simple button that does the following:
    protected void Button1_Click(object sender, EventArgs e)
    {
        flyTreeView.Nodes[0].ChildNodes[1].Remove();
    }


Without success.

Looks the issue is related to server-side templates? Do you use server-side templates for nodes?
Can you create a simple test page with single FlyTreeView control in it that reproduces the issue?
Link Posted: 20-Mar-2009 03:42
[quote="EvgenyT"]Just tried to reproduced using a simple button that does the following:
    protected void Button1_Click(object sender, EventArgs e)
    {
        flyTreeView.Nodes[0].ChildNodes[1].Remove();
    }


Without success.

Looks the issue is related to server-side templates? Do you use server-side templates for nodes?
Can you create a simple test page with single FlyTreeView control in it that reproduces the issue?


My nodes are added in the codebehind only. I'll create a test page and get back to you. I don't even know what these server side templates are.

Conrad
Link Posted: 20-Mar-2009 04:31
Hi Evgeny OK I just created a test page with 2 nodes, a parent and a child node. I then try to delete the child node using the command event of the contextmenu. The menu item is set to Autopostback. The selected node is not null so that could not be causing this error. Here is the entire error message: [code]Server Error in '/' Application. -------------------------------------------------------------------------------- Object reference not set to an instance of an object. Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. Exception Details: System.NullReferenceException: Object reference not set to an instance of an object. Source Error: An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below. Stack Trace: [NullReferenceException: Object reference not set to an instance of an object.] NineRays.WebControls.FlyTreeNode.get_NodeType() +299 NineRays.WebControls.FlyTreeNode.SetContentContainer(Boolean useDataBinding, Boolean useDataBindingSoft) +61 NineRays.WebControls.FlyTreeNode.DataBindContentContainerRecursive() +69 NineRays.WebControls.FlyTreeNode.DataBindContentContainerRecursive() +131 NineRays.WebControls.FlyTreeView.SetContentContainersRecursive() +118 NineRays.WebControls.FlyTreeView.OnPreRender(EventArgs e) +78 System.Web.UI.Control.PreRenderRecursiveInternal() +80 System.Web.UI.Control.PreRenderRecursiveInternal() +171 System.Web.UI.Control.PreRenderRecursiveInternal() +171 System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +842[/code] Here is the code that performs the removal: [code] protected void uxMenu_Command(object sender, NineRays.WebControls.FlyContextMenuCommandEventArgs e) { FlyTreeView1.Nodes.Remove(FlyTreeView1.SelectedNode); } [/code] Here is the markup: [code]
[/code] Please tell me if I am doing anything wrong here? Kind regards Conrad Pienaar
Link Posted: 20-Mar-2009 07:49
Oh, I see. You shouldn't use
FlyTreeView.Nodes.Remove(..) for non-root nodes.

If you change your code to FlyTreeView.Nodes[0].ChildNodes.Remove(..) then it will work.

Anyway a proper code will look like
FlyTreeView.SelectedNode.Remove() - this will cause node to remove itself from paren

Anyway, in your case the code should simply return false and do nothing with FlyTreeView. Instead, it brings FlyTreeView into a wrong state (causing exception). So it is also a FlyTreeView bug, that we'll fix soon (thanks to your help).
Link Posted: 22-Mar-2009 20:51
[quote="EvgenyT"]Oh, I see. You shouldn't use
FlyTreeView.Nodes.Remove(..) for non-root nodes.

If you change your code to FlyTreeView.Nodes[0].ChildNodes.Remove(..) then it will work.

Anyway a proper code will look like
FlyTreeView.SelectedNode.Remove() - this will cause node to remove itself from paren

Anyway, in your case the code should simply return false and do nothing with FlyTreeView. Instead, it brings FlyTreeView into a wrong state (causing exception). So it is also a FlyTreeView bug, that we'll fix soon (thanks to your help).


Hi Evgeny

Thank you. That works great. Thanks for the help and a very good product.

Cheers
Conrad Pienaar