如何在运行时向菜单添加菜单项
我可以动态地将项目添加到菜单吗?我的母版页和服务器端有一个空菜单
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"))
{
}
}
是否可以在母版页服务器端执行此操作。我尝试调试它,错误是空引用异常“对象引用未设置到对象的实例”。我哪里错了。
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". Where am i going wrong.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
应该只是
Session["uPermission"] == null
你不能将ToString()
设为null
Should just be
Session["uPermission"] == null
you can'tToString()
anull
if(Session["uPermission"] == null)
而不是
Session["uPermission"].ToString() == null
if(Session["uPermission"] == null)
rather than
Session["uPermission"].ToString() == null