Home - Forums-.NET - FlyTreeView (ASP.NET) - context menu

FlyTreeView (ASP.NET)

Technical support and KB related to the FlyTreeView control

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

context menu
Link Posted: 18-Sep-2007 10:15
Hi,

i' ve evaluated treeview control and i got a problem with the eventhandler to manage the context menu.

i need to delete a node from database  and the code is the following:

  protected void Page_Load(object sender, EventArgs e)
    {
        
        TreeViewComponent1.menuItem_Event += new  EventHandler(TreeViewComponent1_menuItem_Event);
         if (!IsPostBack)        
            TreeViewComponent1.loadTree();                    
        
    }

public void TreeViewComponent1_menuItem_Event(object sender, FlyContextMenuCommandEventArgs e)
    {        
        String argument=e.CommandArgument.ToString();
        FlyTreeNode node = new FlyTreeNode();
        node = TreeViewComponent1.getNode(e);        
        if (e.CommandName.Equals(\"Delete\")) { }
    
    }

where getnode is:
public FlyTreeNode getNode (FlyContextMenuCommandEventArgs e){

        FlyTreeNode node = new FlyTreeNode();        
        node=flyTreeView.Nodes.FindByID(e.CommandArgument,true);
        FlyTreeNode node1 = new FlyTreeNode();
        node1 = flyTreeView.FindByID(e.CommandArgument);
        return node;
    
    }

but node returns null value, almost i try \" flyTreeView.FindByID\" and \"flyTreeView.Nodes.FindByID\" methods and the result
is not expected, in addition the postback  is undercontrol, but event \"e\" returns i.e. \"n3o05x9w5cc..\" and i've proved
other event types than \"SelectedNodeChangedEventArgs\"  and its behavior is correct  but is not
occurs  the same case with  \"FlyContextMenuCommandEventArgs \"


Thanks in advance for your help.

William
Link Posted: 18-Sep-2007 11:04
Can it be so that you're reinitializing treeview every postback?
So FindByID will always return null, because nodes ID are refreshed.

Also, how do you get into menuItem_Event?
Is the TreeViewComponent1 a kind of some wrapper for flytreeview+contextmenu?
Link Posted: 18-Sep-2007 11:08
Or some test case with the problem that we can run locally - this is always ideal 100% guaranteed way.
Link Posted: 19-Sep-2007 03:06
first thanks for your answer, it's very important

i've   reviewed the reinitilization and the code that prevents that case is :

protected void Page_Load(object sender, EventArgs e)
    {
        
        TreeViewComponent1.menuItem_Event += new EventHandler(TreeViewComponent1_menuItem_Event);
       //load tree  with recent values
       if (!IsPostBack)        
            TreeViewComponent1.loadTree();            
        
        
    }

then treevieew is not  refreshed


But is correct your affirmation: TreeViewComponent1 is a basic wrapper in which i manage the properties for all events..
updating, deleting,selecting... however SelectedNodeChangedEventArgs  no returns the value that i hope

in order to get menuItem_Event i use a independent component :


public partial class components_TreeViewComponent : System.Web.UI.UserControl
{
    protected void Page_Load(object sender, EventArgs e)
    {
        
        if (!IsPostBack)
        {  
            clear();          
            
        }

    }


///
    /// gets the selected node
    ///
    public event System.EventHandler SelectedNode_Event;
    protected void SelectedNode(object sender, NineRays.WebControls.SelectedNodeChangedEventArgs e)
    {
        if (this.SelectedNode_Event != null)      
            SelectedNode_Event(sender, e);        

    }

    public FlyTreeNode getNode (FlyContextMenuCommandEventArgs e){

     FlyTreeNode node = new FlyTreeNode();
     node=flyTreeView.Nodes.FindByID(e.CommandArgument,true);
     FlyTreeNode node1 = new FlyTreeNode();
     node1 = flyTreeView.FindByID(e.CommandArgument);
     return node;

    }




}

the other cases (SelectedNodeChangedEventArgs) the result is perfect.


the page  is the following:

public partial class ProcessEdition : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        
       TreeViewComponent1.menuItem_Event += new EventHandler(TreeViewComponent1_menuItem_Event);
        
        if (!IsPostBack)        
            TreeViewComponent1.loadTree();            
        
        
    }

}


public void TreeViewComponent1_menuItem_Event(object sender, FlyContextMenuCommandEventArgs e)
    {
        TreeViewComponent1.contextMenuID_Event += new EventHandler>(TreeViewComponent1_contextMenuID_Event);
        
        FlyTreeNode node = new FlyTreeNode();
        node = TreeViewComponent1.getNode(e);
        
        if (e.CommandName.Equals(\"Delete\")) { }
    
    }



can i build some code  in javascript in a similar form ?

Thanks in advance for your collaboration.

William
Link Posted: 19-Sep-2007 06:00
I copied your code into my test case. It works perfectly.

Here you can download my code (Page + UserControl):

http://www.9rays.net/forums/downloads/flytreeview_topic1813.zip

Here is what I get when debugging the code (node is not NULL):

Link Posted: 19-Sep-2007 08:39
Hi,

This solution  is correct, in order to the sent code  i've  reviewed my code  and  i found the bug...
i must  to delete the following code in javascript

if (confirm(\"delete current node? \" + node.getValue()))
                            node.remove();


because  this block generates a reload of treeview and then returns null values,sorry  it was  a stupid  mistake


thanks for your excellent collaboration  


William