Adding Menu Item disappears on postback

4 posts, 0 answers
  1. Jon
    Jon avatar
    539 posts
    Member since:
    Apr 2004

    Posted 04 Nov 2008 Link to this post

    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

  2. Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 04 Nov 2008 Link to this post

    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.
  3. Jon
    Jon avatar
    539 posts
    Member since:
    Apr 2004

    Posted 05 Nov 2008 Link to this post

    Same issue
    Any ideas?
    Help
    Thanks
  4. Jon
    Jon avatar
    539 posts
    Member since:
    Apr 2004

    Posted 05 Nov 2008 Link to this post

    I found the issue.. thanks anyway...

    Anyway to cache to menu so I don't have to add the item each time?
    thanks again
Back to Top