This is a migrated thread and some comments may be shown as answers.

Adding Menu Item disappears on postback

3 Answers 26 Views
Menu
This is a migrated thread and some comments may be shown as answers.
Jon
Top achievements
Rank 1
Jon asked on 04 Nov 2008, 11:38 PM
Hi..
I have  masterpage with a menu.. on page load I dynamically load an item. But on PostBack or navigating to other page I loose the MenuItem...
what's wrong.. thanks!

 

// CHECK IF ADMIN

 

 

RadMenuItem NewUser= new RadMenuItem();

 

NewUser.Text =

"Add User";

 

NewUser.ImageUrl =

"img\\user_new.png";

 

NewUser.Value =

"AddUser";

 

 

RadMenuItem admin = this.RadMenu.FindItemByText("Admin");

 

admin.Items.Add(NewUser);

o

3 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 05 Nov 2008, 04:56 AM
Hi Jon,

Try adding the menu item to the corresponding collection first and then set values for its properties as shown below.

CS:
 protected void Page_Load(object sender, EventArgs e)  
    { 
        if (!IsPostBack) 
        { 
            RadMenuItem NewUser = new RadMenuItem(); 
            RadMenuItem admin = this.RadMenu1.FindItemByText("Admin"); 
            admin.Items.Add(NewUser); 
            NewUser.Text = "Add User"
            NewUser.Value = "AddUser"
            
        } 
         
    } 


Thanks
Shinu.
0
Jon
Top achievements
Rank 1
answered on 05 Nov 2008, 12:12 PM
Same issue
Any ideas?
Help
Thanks
0
Jon
Top achievements
Rank 1
answered on 05 Nov 2008, 01:10 PM
I found the issue.. thanks anyway...

Anyway to cache to menu so I don't have to add the item each time?
thanks again
Tags
Menu
Asked by
Jon
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Jon
Top achievements
Rank 1
Share this question
or