|
Rank: Newbie Groups: Member
Joined: 9/17/2009 Posts: 5
|
Hello, i have created a treeview which i fill from codebehind (supposed to be from a db later on), and have a context menu as well. My problem is that the NavigationItemEventArgs.TreeNode is always null, so i cant see on which TreeNode the context menu was opened. I have solved the issue in the meantime by saving the nodevalue in a textbox. but i am hoping to get the other method working. i hope you can tell from my code what i am doing wrong:
Code:
<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="Menu.ascx.cs" Inherits="MenuSystem.Menu" %> <%@ Register TagPrefix="eo" NameSpace="EO.Web" Assembly="EO.Web" %>
<script type="text/javascript">
function ShowContextMenu(e, treeView, node) { var node_value = node.getValue(); //Get the context menu object var menu = eo_GetObject("<%=ContextMenu1.ClientID%>"); //document.getElementById("<%=tbHidden.ClientID%>").value = node.getValue(); document.getElementById("<%=tbHidden.ClientID%>").value = node.getPath(); //Modify the context menu menu.getTopGroup().getItemByIndex(0).setText("Open '" + node.getText() + "'"); menu.getTopGroup().getItemByIndex(1).setText("Delete '" + node.getText() + "'"); //Display the context menu. See documentation //for the Menu control for details about how //to handle menu item click event eo_ShowContextMenu(e, "<%=ContextMenu1.ClientID%>"); //Returns true to indicate that we have //displayed a context menu return true; } </script>
<eo:CallbackPanel ID="cbp" runat="server" Height="230px" > <eo:TreeView ID="tvMenu" runat="server" AutoSelectSource="ItemClick" ControlSkinID="None" OnItemClick="tvMenu_ItemClicked" RaisesServerEvent="True" Height="256px" Width="200px" ClientSideOnContextMenu="ShowContextMenu" > <LookNodes> <eo:TreeNode CollapsedImageUrl="00030201" DisabledStyle-CssText="background-color:transparent;border-bottom-style:none;border-left-style:none;border-right-style:none;border-top-style:none;color:Gray;padding-bottom:1px;padding-left:1px;padding-right:1px;padding-top:1px;" ExpandedImageUrl="00030202" ImageUrl="00030203" ItemID="_Default" NormalStyle-CssText="PADDING-RIGHT: 1px; PADDING-LEFT: 1px; PADDING-BOTTOM: 1px; COLOR: black; BORDER-TOP-STYLE: none; PADDING-TOP: 1px; BORDER-RIGHT-STYLE: none; BORDER-LEFT-STYLE: none; BACKGROUND-COLOR: transparent; BORDER-BOTTOM-STYLE: none" SelectedStyle-CssText="background-color:#316ac5;border-bottom-color:#999999;border-bottom-style:solid;border-bottom-width:1px;border-left-color:#999999;border-left-style:solid;border-left-width:1px;border-right-color:#999999;border-right-style:solid;border-right-width:1px;border-top-color:#999999;border-top-style:solid;border-top-width:1px;color:White;padding-bottom:0px;padding-left:0px;padding-right:0px;padding-top:0px;"> </eo:TreeNode> </LookNodes> <TopGroup Style-CssText="border-bottom-color:#999999;border-bottom-style:solid;border-bottom-width:1px;border-left-color:#999999;border-left-style:solid;border-left-width:1px;border-right-color:#999999;border-right-style:solid;border-right-width:1px;border-top-color:#999999;border-top-style:solid;border-top-width:1px;color:black;cursor:hand;font-family:Tahoma;font-size:8pt;padding-bottom:2px;padding-left:2px;padding-right:2px;padding-top:2px;"> <Nodes> <eo:TreeNode Text="Tilføj node" RaisesServerEvent="True" Value="addNode" > </eo:TreeNode> </Nodes> </TopGroup> </eo:TreeView> </eo:CallbackPanel>
<eo:ContextMenu ID="ContextMenu1" runat="server" ControlSkinID="None" SubMenuIconUrl="Blank" Width="120px" RaisesServerEvent="True" OnItemClick="ContextClick" OnClickScript="OnContextMenuClick" > <LookItems> <eo:MenuItem OnClickScript="OnContextMenuClick" HoverStyle-CssText="BORDER-RIGHT: #9c9a9c 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #9c9a9c 1px solid; PADDING-LEFT: 5px; PADDING-BOTTOM: 2px; BORDER-LEFT: #9c9a9c 1px solid; COLOR: #9c6500; PADDING-TOP: 2px; BORDER-BOTTOM: #9c9a9c 1px solid; BACKGROUND-COLOR: #efefef" ItemID="_Default" LeftIcon-HoverUrl="Triangle1" LeftIcon-SelectedUrl="Blank" LeftIcon-Url="Blank" NormalStyle-CssText="BORDER-RIGHT: #9c9a9c 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #9c9a9c 1px solid; PADDING-LEFT: 5px; PADDING-BOTTOM: 2px; BORDER-LEFT: #9c9a9c 1px solid; COLOR: #003000; PADDING-TOP: 2px; BORDER-BOTTOM: #9c9a9c 1px solid; BACKGROUND-COLOR: #efefef" SelectedStyle-CssText="BORDER-RIGHT: #003000 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #003000 1px solid; PADDING-LEFT: 5px; PADDING-BOTTOM: 2px; BORDER-LEFT: #003000 1px solid; COLOR: white; PADDING-TOP: 2px; BORDER-BOTTOM: #003000 1px solid; BACKGROUND-COLOR: #316531"> <SubMenu ItemSpacing="1" LeftIconCellWidth="7" ShadowDepth="0" Style-CssText="PADDING-RIGHT: 2px; PADDING-LEFT: 2px; FONT-SIZE: 8pt; PADDING-BOTTOM: 2px; CURSOR: hand; COLOR: #003000; BORDER-TOP-STYLE: none; PADDING-TOP: 2px; FONT-FAMILY: Verdana; BORDER-RIGHT-STYLE: none; BORDER-LEFT-STYLE: none; BACKGROUND-COLOR: transparent; BORDER-BOTTOM-STYLE: none"> </SubMenu> </eo:MenuItem> </LookItems> <TopGroup Orientation="Vertical"> <Items> <eo:MenuItem Text-Html="Opret punkt" ToolTip="Opret nyt punkt" CustomItemID="" ItemID="dd1" Value="d1"> </eo:MenuItem> <eo:MenuItem Text-Html="Slet punkt" ToolTip="Slet punkt og eventuelle underpunkter" ItemID="d2" Value="d2"> </eo:MenuItem> <eo:MenuItem Text-Html="Opret niveau" ToolTip="Opret nyt niveau" ItemID="d3" Value="dd3"> </eo:MenuItem> </Items> </TopGroup> </eo:ContextMenu> <p> </p> <p> </p> <asp:TextBox ID="tbHidden" runat="server"></asp:TextBox>
Code: C#
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
//using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using EO.Web;
namespace MenuSystem
{
public partial class Menu : System.Web.UI.UserControl
{
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsCallback)
{
ConstructTree(true);
}
}
private void ConstructTree(bool _editMode)
{
tvMenu.Nodes.Clear();
TreeNode node = new TreeNode("node 1");
node.Value = node.Text;
tvMenu.Nodes.Add(node);
node = new TreeNode("node 2");
node.Value = node.Text;
tvMenu.Nodes.Add(node);
node = new TreeNode("node 3");
node.Value = node.Text;
tvMenu.Nodes.Add(node);
}
protected void tvMenu_ItemClicked(object sender, NavigationItemEventArgs e)
{
//snip
}
public void ContextClick(object sender, NavigationItemEventArgs e)
{
TreeNode node = (TreeNode) tvMenu.FindItem(tbHidden.Text);
}
}
}
best regards Simon
|
|
Rank: Administration Groups: Administration
Joined: 5/27/2007 Posts: 24,194
|
Hi, You don't need to do that. The TreeView already does that for you: http://doc.essentialobjects.com/library/1/eo.web.treeview.contextnode.aspxPlease feel free to let us know if you have any more questions. Thanks!
|
|
Rank: Newbie Groups: Member
Joined: 9/17/2009 Posts: 5
|
Hello, thanks for your fast reply. I tried adding this to my cs file: in the Page_Load method:
Code: C#
tvMenu.ItemClick += new NavigationItemEventHandler(tvMenu_ItemClick);
Code: C#
void tvMenu_ItemClick(object sender, NavigationItemEventArgs e)
{
throw new Exception("test");
}
but i never seem to reach tvMenu_ItemClick with rightclicks from the contextmenu? what do i need to change to make this work? Regards Simon
|
|
Rank: Administration Groups: Administration
Joined: 5/27/2007 Posts: 24,194
|
Hi,
You need to set the menu's RaisesServerEvent to true in order for it to fire server side event.
Thanks
|
|
Rank: Newbie Groups: Member
Joined: 9/17/2009 Posts: 5
|
Hi, i still cant make it work (rasisesserverevent was already true as well).
Code:
<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="Menu.ascx.cs" Inherits="MenuSystem.Menu" %> <%@ Register TagPrefix="eo" NameSpace="EO.Web" Assembly="EO.Web" %>
<script type="text/javascript">
function ShowContextMenu(e, treeView, node) { var node_value = node.getValue(); //Get the context menu object var menu = eo_GetObject("<%=ContextMenu1.ClientID%>"); //document.getElementById("<%=tbHidden.ClientID%>").value = node.getValue(); document.getElementById("<%=tbHidden.ClientID%>").value = node.getPath(); //Modify the context menu menu.getTopGroup().getItemByIndex(0).setText("Open '" + node.getText() + "'"); menu.getTopGroup().getItemByIndex(1).setText("Delete '" + node.getText() + "'"); //Display the context menu. See documentation //for the Menu control for details about how //to handle menu item click event eo_ShowContextMenu(e, "<%=ContextMenu1.ClientID%>"); //Returns true to indicate that we have //displayed a context menu return true; } </script>
<eo:CallbackPanel ID="cbp" runat="server" Height="230px" > <eo:TreeView ID="tvMenu" runat="server" AutoSelectSource="ItemClick" ControlSkinID="None" OnItemClick="tvMenu_ItemClicked" RaisesServerEvent="True" Height="256px" Width="200px" ClientSideOnContextMenu="ShowContextMenu" > <LookNodes> <eo:TreeNode CollapsedImageUrl="00030201" DisabledStyle-CssText="background-color:transparent;border-bottom-style:none;border-left-style:none;border-right-style:none;border-top-style:none;color:Gray;padding-bottom:1px;padding-left:1px;padding-right:1px;padding-top:1px;" ExpandedImageUrl="00030202" ImageUrl="00030203" ItemID="_Default" NormalStyle-CssText="PADDING-RIGHT: 1px; PADDING-LEFT: 1px; PADDING-BOTTOM: 1px; COLOR: black; BORDER-TOP-STYLE: none; PADDING-TOP: 1px; BORDER-RIGHT-STYLE: none; BORDER-LEFT-STYLE: none; BACKGROUND-COLOR: transparent; BORDER-BOTTOM-STYLE: none" SelectedStyle-CssText="background-color:#316ac5;border-bottom-color:#999999;border-bottom-style:solid;border-bottom-width:1px;border-left-color:#999999;border-left-style:solid;border-left-width:1px;border-right-color:#999999;border-right-style:solid;border-right-width:1px;border-top-color:#999999;border-top-style:solid;border-top-width:1px;color:White;padding-bottom:0px;padding-left:0px;padding-right:0px;padding-top:0px;"> </eo:TreeNode> </LookNodes> <TopGroup Style-CssText="border-bottom-color:#999999;border-bottom-style:solid;border-bottom-width:1px;border-left-color:#999999;border-left-style:solid;border-left-width:1px;border-right-color:#999999;border-right-style:solid;border-right-width:1px;border-top-color:#999999;border-top-style:solid;border-top-width:1px;color:black;cursor:hand;font-family:Tahoma;font-size:8pt;padding-bottom:2px;padding-left:2px;padding-right:2px;padding-top:2px;"> <Nodes> <eo:TreeNode Text="Tilføj node" RaisesServerEvent="True" Value="addNode" > </eo:TreeNode> </Nodes> </TopGroup> </eo:TreeView> </eo:CallbackPanel>
<eo:ContextMenu ID="ContextMenu1" runat="server" ControlSkinID="None" SubMenuIconUrl="Blank" Width="120px" RaisesServerEvent="True" > <LookItems> <eo:MenuItem HoverStyle-CssText="BORDER-RIGHT: #9c9a9c 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #9c9a9c 1px solid; PADDING-LEFT: 5px; PADDING-BOTTOM: 2px; BORDER-LEFT: #9c9a9c 1px solid; COLOR: #9c6500; PADDING-TOP: 2px; BORDER-BOTTOM: #9c9a9c 1px solid; BACKGROUND-COLOR: #efefef" ItemID="_Default" LeftIcon-HoverUrl="Triangle1" LeftIcon-SelectedUrl="Blank" LeftIcon-Url="Blank" NormalStyle-CssText="BORDER-RIGHT: #9c9a9c 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #9c9a9c 1px solid; PADDING-LEFT: 5px; PADDING-BOTTOM: 2px; BORDER-LEFT: #9c9a9c 1px solid; COLOR: #003000; PADDING-TOP: 2px; BORDER-BOTTOM: #9c9a9c 1px solid; BACKGROUND-COLOR: #efefef" SelectedStyle-CssText="BORDER-RIGHT: #003000 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #003000 1px solid; PADDING-LEFT: 5px; PADDING-BOTTOM: 2px; BORDER-LEFT: #003000 1px solid; COLOR: white; PADDING-TOP: 2px; BORDER-BOTTOM: #003000 1px solid; BACKGROUND-COLOR: #316531"> <SubMenu ItemSpacing="1" LeftIconCellWidth="7" ShadowDepth="0" Style-CssText="PADDING-RIGHT: 2px; PADDING-LEFT: 2px; FONT-SIZE: 8pt; PADDING-BOTTOM: 2px; CURSOR: hand; COLOR: #003000; BORDER-TOP-STYLE: none; PADDING-TOP: 2px; FONT-FAMILY: Verdana; BORDER-RIGHT-STYLE: none; BORDER-LEFT-STYLE: none; BACKGROUND-COLOR: transparent; BORDER-BOTTOM-STYLE: none"> </SubMenu> </eo:MenuItem> </LookItems> <TopGroup Orientation="Vertical"> <Items> <eo:MenuItem Text-Html="Opret punkt" ToolTip="Opret nyt punkt" ItemID="dd1" Value="d1"> </eo:MenuItem> <eo:MenuItem Text-Html="Slet punkt" ToolTip="Slet punkt og eventuelle underpunkter" ItemID="d2" Value="d2"> </eo:MenuItem> <eo:MenuItem Text-Html="Opret niveau" ToolTip="Opret nyt niveau" ItemID="d3" Value="dd3"> </eo:MenuItem> </Items> </TopGroup> </eo:ContextMenu> <p> </p> <p> </p> <asp:TextBox ID="tbHidden" runat="server"></asp:TextBox>
cs file
Code: C#
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
//using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using EO.Web;
namespace MenuSystem
{
public partial class Menu : System.Web.UI.UserControl
{
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsCallback)
{
tvMenu.ItemClick += new NavigationItemEventHandler(tvMenu_ItemClick);
ConstructTree(true);
}
}
void tvMenu_ItemClick(object sender, NavigationItemEventArgs e)
{
throw new Exception("test");
}
/// <summary>
/// Adds nodes from database
/// </summary>
/// <param name="_editMode">True: adds addNode, False: normal usage</param>
private void ConstructTree(bool _editMode)
{
tvMenu.Nodes.Clear();
TreeNode node = new TreeNode("node 1");
node.Value = node.Text;
tvMenu.Nodes.Add(node);
node = new TreeNode("node 2");
node.Value = node.Text;
tvMenu.Nodes.Add(node);
node = new TreeNode("node 3");
node.Value = node.Text;
tvMenu.Nodes.Add(node);
}
protected void tvMenu_ItemClicked(object sender, NavigationItemEventArgs e)
{
throw new Exception("item clicked");
}
}
}
regards Simon
|
|
Rank: Administration Groups: Administration
Joined: 5/27/2007 Posts: 24,194
|
Hi, Have you tried to move:
Code: C#
tvMenu.ItemClick += new NavigationItemEventHandler(tvMenu_ItemClick);
Outside of if (!Page.IsCallback) block? I believe you need to hook up event handler regardless. You can also hook it up in your .aspx directly (there is no need to do both):
Code: HTML/ASPX
<eo:ContextMenu OnItemClick="tvMenu_ItemClick" ...>
...
</eo:ContextMenu>
Note if you do it this way, you may need to change your event handler from:
Code: C#
void tvMenu_ItemClick(.....)
To:
Code: C#
protected void tvMenu_ItemClick(.....)
Note the added "protected" keyword. Thanks!
|
|
Rank: Newbie Groups: Member
Joined: 9/17/2009 Posts: 5
|
hi, the event fires correctly now, but the e.TreeNode is still null? is it not the correct property to be looking at to get the node?
Code:
<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="Menu.ascx.cs" Inherits="MenuSystem.Menu" %> <%@ Register TagPrefix="eo" NameSpace="EO.Web" Assembly="EO.Web" %>
<script type="text/javascript">
function ShowContextMenu(e, treeView, node) { var node_value = node.getValue(); //Get the context menu object var menu = eo_GetObject("<%=ContextMenu1.ClientID%>"); //document.getElementById("<%=tbHidden.ClientID%>").value = node.getValue(); document.getElementById("<%=tbHidden.ClientID%>").value = node.getPath(); //Modify the context menu menu.getTopGroup().getItemByIndex(0).setText("Open '" + node.getText() + "'"); menu.getTopGroup().getItemByIndex(1).setText("Delete '" + node.getText() + "'"); //Display the context menu. See documentation //for the Menu control for details about how //to handle menu item click event eo_ShowContextMenu(e, "<%=ContextMenu1.ClientID%>"); //Returns true to indicate that we have //displayed a context menu return true; } </script>
<eo:CallbackPanel ID="cbp" runat="server" Height="230px" > <eo:TreeView ID="tvMenu" runat="server" AutoSelectSource="ItemClick" ControlSkinID="None" OnItemClick="tvMenu_ItemClicked" RaisesServerEvent="True" Height="256px" Width="200px" ClientSideOnContextMenu="ShowContextMenu" > <LookNodes> <eo:TreeNode CollapsedImageUrl="00030201" DisabledStyle-CssText="background-color:transparent;border-bottom-style:none;border-left-style:none;border-right-style:none;border-top-style:none;color:Gray;padding-bottom:1px;padding-left:1px;padding-right:1px;padding-top:1px;" ExpandedImageUrl="00030202" ImageUrl="00030203" ItemID="_Default" NormalStyle-CssText="PADDING-RIGHT: 1px; PADDING-LEFT: 1px; PADDING-BOTTOM: 1px; COLOR: black; BORDER-TOP-STYLE: none; PADDING-TOP: 1px; BORDER-RIGHT-STYLE: none; BORDER-LEFT-STYLE: none; BACKGROUND-COLOR: transparent; BORDER-BOTTOM-STYLE: none" SelectedStyle-CssText="background-color:#316ac5;border-bottom-color:#999999;border-bottom-style:solid;border-bottom-width:1px;border-left-color:#999999;border-left-style:solid;border-left-width:1px;border-right-color:#999999;border-right-style:solid;border-right-width:1px;border-top-color:#999999;border-top-style:solid;border-top-width:1px;color:White;padding-bottom:0px;padding-left:0px;padding-right:0px;padding-top:0px;"> </eo:TreeNode> </LookNodes> <TopGroup Style-CssText="border-bottom-color:#999999;border-bottom-style:solid;border-bottom-width:1px;border-left-color:#999999;border-left-style:solid;border-left-width:1px;border-right-color:#999999;border-right-style:solid;border-right-width:1px;border-top-color:#999999;border-top-style:solid;border-top-width:1px;color:black;cursor:hand;font-family:Tahoma;font-size:8pt;padding-bottom:2px;padding-left:2px;padding-right:2px;padding-top:2px;"> <Nodes> <eo:TreeNode Text="Tilføj node" RaisesServerEvent="True" Value="addNode" > </eo:TreeNode> </Nodes> </TopGroup> </eo:TreeView> </eo:CallbackPanel>
<eo:ContextMenu ID="ContextMenu1" runat="server" ControlSkinID="None" SubMenuIconUrl="Blank" Width="120px" RaisesServerEvent="True" OnItemClick="tvMenu_ItemClick" > <LookItems> <eo:MenuItem HoverStyle-CssText="BORDER-RIGHT: #9c9a9c 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #9c9a9c 1px solid; PADDING-LEFT: 5px; PADDING-BOTTOM: 2px; BORDER-LEFT: #9c9a9c 1px solid; COLOR: #9c6500; PADDING-TOP: 2px; BORDER-BOTTOM: #9c9a9c 1px solid; BACKGROUND-COLOR: #efefef" ItemID="_Default" LeftIcon-HoverUrl="Triangle1" LeftIcon-SelectedUrl="Blank" LeftIcon-Url="Blank" NormalStyle-CssText="BORDER-RIGHT: #9c9a9c 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #9c9a9c 1px solid; PADDING-LEFT: 5px; PADDING-BOTTOM: 2px; BORDER-LEFT: #9c9a9c 1px solid; COLOR: #003000; PADDING-TOP: 2px; BORDER-BOTTOM: #9c9a9c 1px solid; BACKGROUND-COLOR: #efefef" SelectedStyle-CssText="BORDER-RIGHT: #003000 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #003000 1px solid; PADDING-LEFT: 5px; PADDING-BOTTOM: 2px; BORDER-LEFT: #003000 1px solid; COLOR: white; PADDING-TOP: 2px; BORDER-BOTTOM: #003000 1px solid; BACKGROUND-COLOR: #316531"> <SubMenu ItemSpacing="1" LeftIconCellWidth="7" ShadowDepth="0" Style-CssText="PADDING-RIGHT: 2px; PADDING-LEFT: 2px; FONT-SIZE: 8pt; PADDING-BOTTOM: 2px; CURSOR: hand; COLOR: #003000; BORDER-TOP-STYLE: none; PADDING-TOP: 2px; FONT-FAMILY: Verdana; BORDER-RIGHT-STYLE: none; BORDER-LEFT-STYLE: none; BACKGROUND-COLOR: transparent; BORDER-BOTTOM-STYLE: none"> </SubMenu> </eo:MenuItem> </LookItems> <TopGroup Orientation="Vertical"> <Items> <eo:MenuItem Text-Html="Opret punkt" ToolTip="Opret nyt punkt" ItemID="" Value="opret punkt value"> </eo:MenuItem> <eo:MenuItem Text-Html="Slet punkt" ToolTip="Slet punkt og eventuelle underpunkter" ItemID="" Value="slet punkt value"> </eo:MenuItem> <eo:MenuItem Text-Html="Opret niveau" ToolTip="Opret nyt niveau" ItemID="" Value="opret niveau value"> </eo:MenuItem> </Items> </TopGroup> </eo:ContextMenu> <p> </p> <p> </p> <asp:TextBox ID="tbHidden" runat="server"></asp:TextBox>
Code: C#
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
//using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using EO.Web;
namespace MenuSystem
{
public partial class Menu : System.Web.UI.UserControl
{
protected void Page_Load(object sender, EventArgs e)
{
tvMenu.ItemClick += new NavigationItemEventHandler(tvMenu_ItemClick);
if (!Page.IsCallback)
{
ConstructTree(true);
}
}
protected void tvMenu_ItemClick(object sender, NavigationItemEventArgs e)
{
TreeNode node_rightClick = e.TreeNode;
}
/// <summary>
/// Adds nodes from database
/// </summary>
/// <param name="_editMode">True: adds addNode, False: normal usage</param>
private void ConstructTree(bool _editMode)
{
tvMenu.Nodes.Clear();
TreeNode node = new TreeNode("node 1");
node.Value = node.Text;
tvMenu.Nodes.Add(node);
node = new TreeNode("node 2");
node.Value = node.Text;
tvMenu.Nodes.Add(node);
node = new TreeNode("node 3");
node.Value = node.Text;
tvMenu.Nodes.Add(node);
}
protected void tvMenu_ItemClicked(object sender, NavigationItemEventArgs e)
{
TreeNode node_leftClick = e.TreeNode;
}
}
}
regards
|
|
Rank: Administration Groups: Administration
Joined: 5/27/2007 Posts: 24,194
|
No. The correct property is this one: http://doc.essentialobjects.com/library/1/eo.web.treeview.contextnode.aspxYou never get a TreeNode out of a Menu's event handler. To get a TreeNode, you will need to get it from the TreeView. Thanks
|
|
Rank: Newbie Groups: Member
Joined: 9/17/2009 Posts: 5
|
Works now, thanks. posting complete code if anyone else needs it:
Code:
<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="Menu.ascx.cs" Inherits="MenuSystem.Menu" %> <%@ Register TagPrefix="eo" NameSpace="EO.Web" Assembly="EO.Web" %>
<script type="text/javascript">
function ShowContextMenu(e, treeView, node) { var node_value = node.getValue(); //Get the context menu object var menu = eo_GetObject("<%=ContextMenu1.ClientID%>"); //document.getElementById("<%=tbHidden.ClientID%>").value = node.getValue(); document.getElementById("<%=tbHidden.ClientID%>").value = node.getPath(); //Modify the context menu menu.getTopGroup().getItemByIndex(0).setText("Open '" + node.getText() + "'"); menu.getTopGroup().getItemByIndex(1).setText("Delete '" + node.getText() + "'"); //Display the context menu. See documentation //for the Menu control for details about how //to handle menu item click event eo_ShowContextMenu(e, "<%=ContextMenu1.ClientID%>"); //Returns true to indicate that we have //displayed a context menu return true; } </script>
<eo:CallbackPanel ID="cbp" runat="server" Height="230px" > <eo:TreeView ID="tvMenu" runat="server" AutoSelectSource="ItemClick" ControlSkinID="None" OnItemClick="tvMenu_ItemClicked" RaisesServerEvent="True" Height="256px" Width="200px" ClientSideOnContextMenu="ShowContextMenu" > <LookNodes> <eo:TreeNode CollapsedImageUrl="00030201" DisabledStyle-CssText="background-color:transparent;border-bottom-style:none;border-left-style:none;border-right-style:none;border-top-style:none;color:Gray;padding-bottom:1px;padding-left:1px;padding-right:1px;padding-top:1px;" ExpandedImageUrl="00030202" ImageUrl="00030203" ItemID="_Default" NormalStyle-CssText="PADDING-RIGHT: 1px; PADDING-LEFT: 1px; PADDING-BOTTOM: 1px; COLOR: black; BORDER-TOP-STYLE: none; PADDING-TOP: 1px; BORDER-RIGHT-STYLE: none; BORDER-LEFT-STYLE: none; BACKGROUND-COLOR: transparent; BORDER-BOTTOM-STYLE: none" SelectedStyle-CssText="background-color:#316ac5;border-bottom-color:#999999;border-bottom-style:solid;border-bottom-width:1px;border-left-color:#999999;border-left-style:solid;border-left-width:1px;border-right-color:#999999;border-right-style:solid;border-right-width:1px;border-top-color:#999999;border-top-style:solid;border-top-width:1px;color:White;padding-bottom:0px;padding-left:0px;padding-right:0px;padding-top:0px;"> </eo:TreeNode> </LookNodes> <TopGroup Style-CssText="border-bottom-color:#999999;border-bottom-style:solid;border-bottom-width:1px;border-left-color:#999999;border-left-style:solid;border-left-width:1px;border-right-color:#999999;border-right-style:solid;border-right-width:1px;border-top-color:#999999;border-top-style:solid;border-top-width:1px;color:black;cursor:hand;font-family:Tahoma;font-size:8pt;padding-bottom:2px;padding-left:2px;padding-right:2px;padding-top:2px;"> <Nodes> <eo:TreeNode Text="Tilføj node" RaisesServerEvent="True" Value="addNode" > </eo:TreeNode> </Nodes> </TopGroup> </eo:TreeView> </eo:CallbackPanel>
<eo:ContextMenu ID="ContextMenu1" runat="server" ControlSkinID="None" SubMenuIconUrl="Blank" Width="120px" RaisesServerEvent="True" OnItemClick="tvMenu_ItemClick" > <LookItems> <eo:MenuItem HoverStyle-CssText="BORDER-RIGHT: #9c9a9c 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #9c9a9c 1px solid; PADDING-LEFT: 5px; PADDING-BOTTOM: 2px; BORDER-LEFT: #9c9a9c 1px solid; COLOR: #9c6500; PADDING-TOP: 2px; BORDER-BOTTOM: #9c9a9c 1px solid; BACKGROUND-COLOR: #efefef" ItemID="_Default" LeftIcon-HoverUrl="Triangle1" LeftIcon-SelectedUrl="Blank" LeftIcon-Url="Blank" NormalStyle-CssText="BORDER-RIGHT: #9c9a9c 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #9c9a9c 1px solid; PADDING-LEFT: 5px; PADDING-BOTTOM: 2px; BORDER-LEFT: #9c9a9c 1px solid; COLOR: #003000; PADDING-TOP: 2px; BORDER-BOTTOM: #9c9a9c 1px solid; BACKGROUND-COLOR: #efefef" SelectedStyle-CssText="BORDER-RIGHT: #003000 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #003000 1px solid; PADDING-LEFT: 5px; PADDING-BOTTOM: 2px; BORDER-LEFT: #003000 1px solid; COLOR: white; PADDING-TOP: 2px; BORDER-BOTTOM: #003000 1px solid; BACKGROUND-COLOR: #316531"> <SubMenu ItemSpacing="1" LeftIconCellWidth="7" ShadowDepth="0" Style-CssText="PADDING-RIGHT: 2px; PADDING-LEFT: 2px; FONT-SIZE: 8pt; PADDING-BOTTOM: 2px; CURSOR: hand; COLOR: #003000; BORDER-TOP-STYLE: none; PADDING-TOP: 2px; FONT-FAMILY: Verdana; BORDER-RIGHT-STYLE: none; BORDER-LEFT-STYLE: none; BACKGROUND-COLOR: transparent; BORDER-BOTTOM-STYLE: none"> </SubMenu> </eo:MenuItem> </LookItems> <TopGroup Orientation="Vertical"> <Items> <eo:MenuItem Text-Html="Opret punkt" ToolTip="Opret nyt punkt" ItemID="" Value="opret punkt value"> </eo:MenuItem> <eo:MenuItem Text-Html="Slet punkt" ToolTip="Slet punkt og eventuelle underpunkter" ItemID="" Value="slet punkt value"> </eo:MenuItem> <eo:MenuItem Text-Html="Opret niveau" ToolTip="Opret nyt niveau" ItemID="" Value="opret niveau value"> </eo:MenuItem> </Items> </TopGroup> </eo:ContextMenu> <p> </p> <p> </p> <asp:TextBox ID="tbHidden" runat="server"></asp:TextBox>
Code: C#
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
//using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using EO.Web;
namespace MenuSystem
{
public partial class Menu : System.Web.UI.UserControl
{
protected void Page_Load(object sender, EventArgs e)
{
//tvMenu.ItemClick += new NavigationItemEventHandler(tvMenu_ItemClick);
if (!Page.IsCallback)
{
ConstructTree(true);
}
}
protected void tvMenu_ItemClick(object sender, NavigationItemEventArgs e)
{
TreeNode contextNode = tvMenu.ContextNode;
if (contextNode != null)
{
System.Console.WriteLine("right click: " + contextNode.Text);
}
}
/// <summary>
/// Adds nodes from database
/// </summary>
/// <param name="_editMode">True: adds addNode, False: normal usage</param>
private void ConstructTree(bool _editMode)
{
tvMenu.Nodes.Clear();
TreeNode node = new TreeNode("node 1");
node.Value = node.Text;
tvMenu.Nodes.Add(node);
node = new TreeNode("node 2");
node.Value = node.Text;
tvMenu.Nodes.Add(node);
node = new TreeNode("node 3");
node.Value = node.Text;
tvMenu.Nodes.Add(node);
}
protected void tvMenu_ItemClicked(object sender, NavigationItemEventArgs e)
{
TreeNode node_leftClick = e.TreeNode;
System.Console.WriteLine("left click: " + node_leftClick.Text);
}
}
}
thanks! Simon
|
|
Rank: Administration Groups: Administration
Joined: 5/27/2007 Posts: 24,194
|
Great. Thanks for the update!
|
|