Welcome Guest Search | Active Topics | Sign In | Register

Can not get ItemClick event from ContextMenu control. Options
Jack.Wu
Posted: Monday, May 10, 2010 9:52:59 PM
Rank: Advanced Member
Groups: Member

Joined: 5/22/2009
Posts: 33
Hello Sir,

I am trying to use a TreeView with ContextMenu but experiencing some problems as following:
1. There is no document or example to show me how to get the ItemClick event.
2. There is no document or example for OnClientScript property of MenuItem in the ContextMenu

After I try the ItemClick event of ContrxtMenu, found that it can not be fired in the server side. Please help to show me the correct way to get the ItemClick event or let me know how to get informed on the client side.

This is the user control I used:

<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="ItemTree.ascx.cs" Inherits="KosmasWebTest.Control.ItemTree" %>
<%@ Register TagPrefix="eo" NameSpace="EO.Web" Assembly="EO.Web" %>
<script type="text/javascript">

function ShowContextMenu(e, treeView, node)
{
//Get the context menu object
var menu = eo_GetObject("<%=Menu1.ClientID%>");

//Modify the context menu
// menu.getTopGroup().getItemByIndex(0).setText("Insert '" + 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, "<%=Menu1.ClientID%>");

//Returns true to indicate that we have
//displayed a context menu
return true;
}

</script>
<eo:TreeView runat="server" id="TreeView1" Width="200px" ControlSkinID="None" Height="250px"
ClientSideOnContextMenu="ShowContextMenu" AllowDragDrop="True" AllowDragReordering="True" AllowEdit="True">
<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="Documents and Settings">
<SubGroup>
<Nodes>
<eo:TreeNode Text="Administrator"></eo:TreeNode>
<eo:TreeNode Text="All Users"></eo:TreeNode>
<eo:TreeNode Text="Default User"></eo:TreeNode>
</Nodes>
</SubGroup>
</eo:TreeNode>
<eo:TreeNode Text="Program Files">
<SubGroup>
<Nodes>
<eo:TreeNode Text="Common Files"></eo:TreeNode>
<eo:TreeNode Text="ComPlus Applications"></eo:TreeNode>
<eo:TreeNode Text="Internet Explorer"></eo:TreeNode>
<eo:TreeNode Text="MSDN"></eo:TreeNode>
</Nodes>
</SubGroup>
</eo:TreeNode>
<eo:TreeNode Text="Windows">
<SubGroup>
<Nodes>
<eo:TreeNode Text="Fonts"></eo:TreeNode>
<eo:TreeNode Text="Help"></eo:TreeNode>
<eo:TreeNode Text="System32"></eo:TreeNode>
</Nodes>
</SubGroup>
</eo:TreeNode>
</Nodes>
</TopGroup>
<LookNodes>
<eo:TreeNode CollapsedImageUrl="00030301" 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="00030302" ImageUrl="00030301" 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>
</eo:TreeView>
<eo:ContextMenu id="Menu1" Width="144px" runat="server" ControlSkinID="None" OnItemClick="Menu1_ItemClick">
<TopGroup Style-CssText="cursor:hand;font-family:Verdana;font-size:11px;">
<Items>
<eo:MenuItem Text-Html="新增" LeftIcon-Url="00101001"></eo:MenuItem>
<eo:MenuItem Text-Html="刪除" LeftIcon-Url="00000208"></eo:MenuItem>
</Items>
</TopGroup>
<LookItems>
<eo:MenuItem IsSeparator="True" ItemID="_Separator" NormalStyle-CssText="background-color:#E0E0E0;height:1px;width:1px;">
</eo:MenuItem>
<eo:MenuItem HoverStyle-CssText="color:#F7B00A;padding-left:5px;padding-right:5px;"
ItemID="_Default" NormalStyle-CssText="padding-left:5px;padding-right:5px;">
<SubMenu CollapseEffect-Type="GlideTopToBottom" ExpandEffect-Type="GlideTopToBottom"
ItemSpacing="5" OffsetX="3" OffsetY="-4" ShadowDepth="0" Style-CssText="border-right: #e0e0e0 1px solid; padding-right: 3px; border-top: #e0e0e0 1px solid; padding-left: 3px; font-size: 12px; padding-bottom: 3px; border-left: #e0e0e0 1px solid; cursor: hand; color: #606060; padding-top: 3px; border-bottom: #e0e0e0 1px solid; font-family: arial; background-color: #f7f8f9">
</SubMenu>
</eo:MenuItem>
</LookItems>
</eo:ContextMenu>

The codebehind as following:
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

namespace KosmasWebTest.Control
{
public partial class ItemTree : System.Web.UI.UserControl
{
protected void Page_Load(object sender, EventArgs e)
{

}

protected void Menu1_ItemClick(object sender, EO.Web.NavigationItemEventArgs e)
{
string msg;

Response.Write(e.MenuItem.Text);
}
}
}

eo_support
Posted: Tuesday, May 11, 2010 8:27:50 AM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 24,194
Hi,

ContextMenu derives from Menu control. So everything is the same as a Menu control. Please refer to Menu contro's documentation for more details:

http://doc.essentialobjects.com/library/1/menucommon/handlingevent/server_event.aspx
http://doc.essentialobjects.com/library/1/menucommon/handlingevent/client_event.aspx

Thanks!


You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.