开发者

How to add menu items to menu at runtime

开发者 https://www.devze.com 2023-04-06 09:38 出处:网络
Can I add items to menu dynamically, I have a empty menu in my master page and in server side Page load()

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

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号