Click here to Skip to main content
15,921,351 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
VB
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




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..
Posted
Comments
Sandeep Mewara 5-Mar-11 6:11am    
So, what is 'StepPlanMenu1'. Where is it declared?
priya0809 5-Mar-11 6:16am    
'StepPlanMenu1' is Menu which I added on design time at source file...

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.
 
Share this answer
 
Comments
Sandeep Mewara 5-Mar-11 6:19am    
Comment from OP:
Sorry But I had already seen that code , Problem is what ,

In your suggested code menu is also creating dynamaticaly but in My code I used Menu in design time then added its item at run time on Code behind according to above method..but Menu what I created on design time has Value nothing means null thats why its showing exception of Object reference not found...
Hi
If you are using master page then you have to access it from the master page as below
C#
if (!IsPostBack)
{
    MenuItem mItem1 = new MenuItem();
    mItem1.Text = "Test Menu";
    Menu menu = (Menu)this.Master.FindControl("NavigationMenu");
    menu.Items.Add(mItem1);
}


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

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900