开发者

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

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜