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". Where am i going wrong. 开发者_运维技巧
Session["uPermission"].ToString() == null
Should just be Session["uPermission"] == null
you can't ToString()
a null
if(Session["uPermission"] == null)
rather than Session["uPermission"].ToString() == null
精彩评论