Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
45
Add items to WebMenu inside WARP
posted

Hi, i have a WebMenu "Menu1" inside a WebAsyncRefreshPanel.

Adding Menu Items programatically to the Menu works but after 1st postback the programatically added Menu Items do not longer exists.

protected void Page_Load( object sender, EventArgs e )
{
    if ( IsPostBack )
    {
        // load menu definition from database
        MenuInfo menuInfo = new MenuInfo( dbSession, ....... )

        foreach( MenuItemInfo menuItemInfo in menuInfo)
        {
            Item menuItem2 = Menu1.Items.Add( new Item() );
            menuItem2.Text = "Test 1.1";
            menuItem2.Tag = "TEST11";
        }
    }
}

 

  • 2677
    posted

    Hello,

    I'm not sure what the problem could be.  However, on thing that I do notice is that you are adding MenuItems on each postback.  So, what should happen is every PostBack, the same set of items will be added to the Menu and you will get a long list of the same menuItems.  Is that what you want to do?  You may want to try using the ! symbol before IsPostBack. 

     if ( !IsPostBack )

    Then, you will be sure that the items from the menu will be loaded on the initial page load and not on ever postback. 

     However, even when I tried code very similar to yours (I did a for loop instead of a foreach loop the that loops through numbers rather then this MenuInfo collection) and I was unable to get them to disappear.

    if ( !IsPostBack )
            {
                for (int i = 0; i < 5; i++)
                {
                    Item menuItem2 = UltraWebMenu1.Items.Add(new Item());
                    menuItem2.Text = "Test 1." + i.ToString();
                    menuItem2.Tag = "TEST1." + i.ToString();
                } 
            }

    If you are still having problems working with the WebMenu, please contact Developer Support and they will be able to help you solve your issue.