[CLOSED] Dynamic menu items in menu panel creation problem

  1. #1

    [CLOSED] Dynamic menu items in menu panel creation problem

    i have implemented a Dynamic Menu panel in My Application

    The Problem am Facing is on "Page_Load" the Menus will be created thats fine,
    but during other operation in my application i need to add more menus to the menupanel,
    and am calling the method "LoadMenu()" on button click "btnAddMoreMenu_click" and that regenerates the menus
    and even it adds some new menu items to MenuPanel. but the Newly created menus are not reflected on the client side UI.
    I want to achieve this with out refreshing the Page.

    
    <%@ Page Language="C#" AutoEventWireup="true" CodeFile="Question1.aspx.cs" Inherits="Question1" %>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <%@ Register Assembly="Ext.Net" Namespace="Ext.Net" TagPrefix="ext" %>
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
        <title>Question1</title>
        <style type="text/css">
            .x-menu.x-menu-horizontal .x-menu-list
            {
                overflow: hidden;
            }
            .x-menu.x-menu-horizontal .x-menu-list .x-menu-list-item
            {
                float: left;
            }
            .x-menu.x-menu-horizontal .x-menu-list .x-menu-list-item .x-menu-item-arrow
            {
                background: none;
            }
        </style>
    </head>
    <body>
        <form id="form1" runat="server">
        <ext:ResourceManager ID="ResourceManager1" runat="server" /> 
        <ext:Viewport ID="ViewPort1" runat="server" Layout="FitLayout" AutoScroll="true">
            <Items>
                <ext:Panel ID="pnlTop" runat="server" Height="106"
                    BodyBorder="false" Border="false" Region="Center">
                    <Items>
                        <ext:MenuPanel ID="mPnlMain" runat="server" Border="false" Region="North" Height="30">
                            <Menu ID="mnuMain" runat="server" Hidden="false" ShowSeparator="true" EnableScrolling="false"
                                SubMenuAlign="tl-bl?" Cls="x-menu-horizontal" Floating="false">
                            </Menu>
                        </ext:MenuPanel>
                        <ext:Button ID="btnAddMoreMenu" runat="server" Text="Add More Menus">
                            <DirectEvents>
                                <Click OnEvent="btnAddMoreMenu_click" />
                            </DirectEvents>
                        </ext:Button>
                    </Items>
                </ext:Panel>
            </Items>
        </ext:Viewport>
        </form>
    </body>
    </html>
    
    
    using System;
    using System.Collections;
    using System.Configuration;
    using System.Data;
    using System.Linq;
    using System.Web;
    using System.Web.Security;
    using System.Web.UI;
    using System.Web.UI.HtmlControls;
    using System.Web.UI.WebControls;
    using System.Web.UI.WebControls.WebParts;
    using System.Xml.Linq;
    using Ext.Net;
    
    public partial class Question1 : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            LoadMenu();
        }
    
        public void LoadMenu()
        {
            Ext.Net.MenuItem mMenuItem = null;
    
            for (int i = 0; i < 3; i++)
            {
                mMenuItem = new Ext.Net.MenuItem();
                mMenuItem.ID = "Menu_" + i.ToString() + "_" + DateTime.Now.Minute.ToString();
                mMenuItem.Text = "Menu_" + i.ToString() + "_" + DateTime.Now.Minute.ToString();
                mMenuItem.Listeners.Click.Handler = "alert('" + mMenuItem.Text + "');";
                mPnlMain.Menu.Items.Add(mMenuItem);
                mMenuItem = null;
    
                X.AddScript("mPnlMain.doLayout();");
            }
        }
    
        protected void btnAddMoreMenu_click(object sender, DirectEventArgs e)
        {
            LoadMenu();
        }
    }
    Last edited by Daniil; Jan 10, 2013 at 10:42 AM. Reason: [CLOSED]
  2. #2
    Hi @legaldiscovery,

    To render a control during a DirectEvent you should call a special method like Render.

    Example
    if (X.IsAjaxRequest)
    {
        mMenuItem.Render();
    }
    Please note that the Render method should not be called during initial page load.

    See also
    https://examples1.ext.net/#/XRender/Basic/New_Window/
    https://examples1.ext.net/#/XRender/Basic/Add_Items/
  3. #3
    Quote Originally Posted by Daniil View Post
    Hi @legaldiscovery,

    To render a control during a DirectEvent you should call a special method like Render.

    Example
    if (X.IsAjaxRequest)
    {
        mMenuItem.Render();
    }
    Please note that the Render method should not be called during initial page load.

    See also
    https://examples1.ext.net/#/XRender/Basic/New_Window/
    https://examples1.ext.net/#/XRender/Basic/Add_Items/
    Thanx for the solution you can mark this as solved

Similar Threads

  1. Replies: 0
    Last Post: Aug 09, 2012, 5:37 AM
  2. Replies: 2
    Last Post: Apr 02, 2012, 7:48 AM
  3. Replies: 11
    Last Post: Aug 30, 2010, 9:28 PM
  4. Dynamic context menu items
    By JonG in forum 1.x Help
    Replies: 2
    Last Post: Nov 26, 2009, 7:37 AM
  5. [CLOSED] [1.0] MVC sample west menu has no menu items
    By Inoventus in forum 1.x Legacy Premium Help
    Replies: 9
    Last Post: Nov 24, 2009, 4:06 AM

Posting Permissions