asp.net2.0Menu问题
我在做了一个菜单导航:
代码如下:1.前台
<table style= "width:100% ">
<tr>
<td align= "right " valign= "top ">
<asp:Menu ID= "ManageMenu " runat= "server " ToolTip= "Manage " OnMenuItemDataBound= "ManageMenu_MenuItemDataBound " OnInit= "ManageMenu_Init " OnMenuItemClick= "ManageMenu_MenuItemClick " DataSourceID= "SamplesSiteMap ">
<StaticItemTemplate>
<asp:LinkButton ID= "LinkButton1 " runat= "server " CommandName= ' <%# Eval( "Text ") %> '
Text= ' <%# Eval( "Text ") %> ' OnClick= "LinkButton1_Click "> </asp:LinkButton>
</StaticItemTemplate>
<DynamicItemTemplate>
<asp:LinkButton ID= "LinkButton1 " runat= "server " CommandName= ' <%# Eval( "Text ") %> '
Text= ' <%# Eval( "Text ") %> '> </asp:LinkButton>
</DynamicItemTemplate>
</asp:Menu>
<asp:SiteMapDataSource ID= "SamplesSiteMap " runat= "server " SiteMapProvider= "SamplesSiteMap "/>
</td>
</tr>
</table>
说明:我的Menu绑定到了一个SamplesSiteMap.sitemap上面.
当然我已经事先在web.config上面配置过了文件如下:
<system.web>
<siteMap defaultProvider= "SamplesSiteMap ">
<providers>
<add name= "SamplesSiteMap " type= "System.Web.XmlSiteMapProvider " siteMapFile= "~/Admin/Skin/Banner/QuickMenu.sitemap "/>
</providers>
</siteMap>
</system.web>
2.sitemap代码:
<?xml version= "1.0 " encoding= "utf-8 " ?>
<siteMap xmlns= "http://schemas.microsoft.com/AspNet/SiteMap-File-1.0 " >
<!--Management-->
<siteMapNode url= " " title= "Management " description= " " roles= "3 ">
<!--Page Function-->
<siteMapNode url= " " title= "Page Function " description= " " roles= "1 ">
<siteMapNode url= " " title= "Add " description= " " roles= "1 "> </siteMapNode>
<siteMapNode url= " " title= "Settings " description= " " roles= "1 "> </siteMapNode>
<siteMapNode url= " " title= "Deletes " description= " " roles= "1 "> </siteMapNode>
</siteMapNode>
<!--Add Modules-->
<siteMapNode url= " " title= "Add Modules " description= " " roles= "1 " resourceKey= " " > </siteMapNode>
<!--Comman Task-->
<siteMapNode url= " " title= "Comman Task " description= " " roles= "1 ">
<siteMapNode url= " " title= "Wizard " description= " " roles= "1 "> </siteMapNode>
<siteMapNode url= " " title= "Site " description= " " roles= "1 "> </siteMapNode>
<siteMapNode url= " " title= "Users " description= " " roles= "1 "> </siteMapNode>
<siteMapNode url= " " title= "Helps " description= " " roles= "1 "> </siteMapNode>
</siteMapNode>
<!--User Customization-->
<siteMapNode url= " " title= "User Customization " description= " " roles= "3 ">
<siteMapNode url= " " title= "Theme " description= " " roles= "3 ">
<siteMapNode url= " " title= "Red " description= " " roles= "3 "> </siteMapNode>
<siteMapNode url= " " title= "Orange " description= " " roles= "3 "> </siteMapNode>
<siteMapNode url= " " title= "Yellow " description= " " roles= "3 "> </siteMapNode>
<siteMapNode url= " " title= "Green " description= " " roles= "3 "> </siteMapNode>
<siteMapNode url= " " title= "DeeplyGreen " description= " " roles= "3 "> </siteMapNode>
<siteMapNode url= " " title= "Blue " description= " " roles= "3 "> </siteMapNode>
<siteMapNode url= " " title= "Color1 " description= " " roles= "3 "> </siteMapNode>
<siteMapNode url= " " title= "Color2 " description= " " roles= "3 "> </siteMapNode>
</siteMapNode>
<siteMapNode url= " " title= "Layout " description= " " roles= "3 ">
<siteMapNode url= " " title= "Horizontal_Edge " description= " " roles= "3 "> </siteMapNode>
<siteMapNode url= " " title= "Horizontal_Fixed " description= " " roles= "3 "> </siteMapNode>
<siteMapNode url= " " title= "Horizontal_Full " description= " " roles= "3 "> </siteMapNode>
<siteMapNode url= " " title= "Vertical_Edge " description= " " roles= "3 "> </siteMapNode>
<siteMapNode url= " " title= "Vertical_Fixed " description= " " roles= "3 "> </siteMapNode>
<siteMapNode url= " " title= "Vertical_Full " description= " " roles= "3 "> </siteMapNode>
</siteMapNode>
<siteMapNode url= " " title= "Language " description= " " roles= "3 ">
<siteMapNode url= " " title= "Chinese " description= " " roles= "3 " resourceKey= " "> </siteMapNode>
<siteMapNode url= "~/Default.aspx " title= "English " description= " " roles= "3 " resourceKey= " "> </siteMapNode>
</siteMapNode>
</siteMapNode>
</siteMapNode>
</siteMap>
3.请您注意这是后台代码,问题也出在这里,当你点击menu的时候 protected void ManageMenu_MenuItemClick(object sender, MenuEventArgs e)
menu的点击事件为何不触发????但是我已经试验过了,当menu是前台用vs工具静态
生成的时候,点击事件是可以及触发的.
public partial class QuickMenu : System.Web.UI.UserControl
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void ManageMenu_MenuItemDataBound(object sender, MenuEventArgs e)
{
Menu menu = sender as Menu;
MenuItem item = e.Item;
DsUserSettings dus = HttpContext.Current.Session[ "UserSetting "] as DsUserSettings;
DsUserSettings.UserSettingsRow UserRow = dus.UserSettings[0];
if (item != null)
{
SiteMapNode no = item.DataItem as SiteMapNode;
if (int.Parse(no.Roles[0].ToString()) != UserRow.RoleID && int.Parse(no.Roles[0].ToString()) != 3)
{
item.Parent.ChildItems.Remove(item);
}
}
}
protected void Menu1_MenuItemClick(object sender, MenuEventArgs e)
{
}
protected void ManageMenu_Init(object sender, EventArgs e)
{
}
protected void ManageMenu_MenuItemClick(object sender, MenuEventArgs e)
{
if (e.CommandName == "ASDF ")
{
}
}
我要实现的功能也很简单,当点击菜单的时候不跳页,直接加载别的usercontrol谢谢大家,以上代码是可以运行过去的
[解决办法]
贴子顶部的管理
不过,不能给自己分
[解决办法]
。。