[英]How to add menu items to menu at runtime
Can I add items to menu dynamically, I have a empty menu in my master page and in server side 我可以动态添加项目到菜单吗,我的主页和服务器端都有一个空菜单
Page load()
{
NavigationMenu.Items.Add(new MenuItem
{
Text = "About Us",
NavigateUrl = "~/AboutUs.aspx"
});
if ((Session["uPermission"].ToString() == null))
{
NavigationMenu.Items.Add(new MenuItem
{
Text = " Support",
NavigateUrl = "~/Support.aspx"
});
}
else if ((Session["uPermission"].ToString() == "SuperAdmin") || (Session["uPermission"].ToString() == "OrgAdmin"))
{
}
}
Is it possible to do this in master page server side. 是否可以在母版页服务器端执行此操作。 I tried debugging it and the error is Null reference exception"Object reference not set to an instance of an object".
我尝试调试它,错误是Null引用异常“对象引用未设置为对象的实例”。 Where am i going wrong.
我要去哪里错了。
Session["uPermission"].ToString() == null
应该只是Session["uPermission"] == null
您不能ToString()
null
if(Session["uPermission"] == null)
而不是Session["uPermission"].ToString() == null
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.