在后台代码中以编程方式添加菜单项,并且未找到对象引用的错误 [英] Adding Menu Item programitacly in Code Behind and getting error of Object refrence not found

查看:48
本文介绍了在后台代码中以编程方式添加菜单项,并且未找到对象引用的错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

If Not IsPostBack Then
    Dim item As MenuItem
    item = New MenuItem()


    item.Text = approve.DisplayStepPlan(4674, "")

    item.Value = "0"
    lblTitle.Text = "A"


    'Dim Menu As Menu = FindControl("StepPlanMenu1")

    StepPlanMenu1.Items.Add(item)
    ' Me.Controls.Add(StepPlanMenu1)



End If





我根据上述代码添加了菜单项,但ID为 StepPlanMenu1 的菜单在运行时未显示任何内容……并且未找到对象引用的抛出异常..请尽快帮助我.

在此先感谢..





I added Menu Item according to above code but Menu which id is StepPlanMenu1 is showing Nothing in code behind at run time ...and Throwing exception of Object reference not found ..Please help me as soon as Possible.

Thanks in Advance..

推荐答案

http://www.eggheadcafe.com/community/aspnet/17/10213509/create-menu-at-run-time.aspx[^]

If i misunderstand your question, please feel free to correct me.
I hope the above information will be helpful. If you have more concerns, please let me know.


您好
如果您正在使用母版页,则必须从母版页访问它,如下所示
Hi
If you are using master page then you have to access it from the master page as below
if (!IsPostBack)
{
    MenuItem mItem1 = new MenuItem();
    mItem1.Text = "Test Menu";
    Menu menu = (Menu)this.Master.FindControl("NavigationMenu");
    menu.Items.Add(mItem1);
}



我认为vb.net可能像Dim menu as Menu= Me.Master.FindControl("StepPlanMenu1")



I think vb.net it may be like Dim menu as Menu= Me.Master.FindControl("StepPlanMenu1")


这篇关于在后台代码中以编程方式添加菜单项,并且未找到对象引用的错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆