[CLOSED] Dynamic created MenuItems and directEvents

  1. #1

    [CLOSED] Dynamic created MenuItems and directEvents

    Releated to the following topic Disable a MenuItem when button selected I began to add click directevents so that the server could load new data into the grid, but I received the following error:

    The control with ID 'CfdbVer24' not found.
    Below is a seqment of the code:

    ...
     <TopBar>
        <ext:Toolbar runat="server">
          <Items>
              <ext:Button runat="server" Icon="Database" >
                 <Menu>
                    <ext:Menu ID="CfdbOptionsMenu" runat="server">
                   <%-- MenuItems dynamically create in behind code --%>
                 </Menu>
              </ext:Button>
              <ext:Label ID="CfdbVersionTitle" runat="server" />
           </Items>
        </ext:Toolbar>
     </TopBar>
     ...
    protected void Page_Load(object sender, EventArgs e) {
        if (!X.IsAjaxRequest)    {
           CFVDataContext dc = new CFVDataContext;
    
           // Retrieve all available versions that can be selected.
           var q = from c in dc.CfdbVersions
                      where c.IsActive == true
                      orderby c.Order descending
                      select c;
           // Create the menu items
           foreach (var c in q)
              {
              Ext.Net.MenuItems item = new Ext.Net.MenuItems() {
                 ID = "CfdbVer" + c.CfdbVer.ToString(),
                 Text = c.Description,
                 Icon = Icon.Database
              };
    
              item.DirectEvents.Click.Event += SelectCfdbVersion;
    
              Ext.Net.Parameter prmVer = new Ext.Net.Parameter() {
                 Name = "Version",
                 Value = c.CfdbVer.ToString(),
                 Mode = Parameter.Value
              }
             item.DirectEvents.Click.ExtraParams.Add(prmVer);
    
               Ext.Net.Parameter prmDesc = new Ext.Net.Parameter() {
                 Name = "Description",
                 Value = c.Description,
                 Mode = Parameter.Value
              }
             item.DirectEvents.Click.ExtraParams.Add(prmDesc);
    
             item.addTo(CfdbOptionsMenu);
           }
        }
     }
    protected void SelectCfdbVersion (object sender, DirectEventArgs e)
    {
       string Description = e.ExtraParams["Description"];
       string version = e.ExtraParams["Version"];
    }
    I found the following thread Gridpanel Directevent in code behind and removed the test of "if (!X.IsAjaxRequest) { }" from the Page_Load method and I am still having an issue.

    Do you have any additional suggestions or examples.
    Last edited by Daniil; Jun 14, 2012 at 5:25 PM. Reason: [CLOSED]
  2. #2
    Hi,

    Quote Originally Posted by cwolcott View Post
    I found the following thread Gridpanel Directevent in code behind and removed the test of "if (!X.IsAjaxRequest) { }" from the Page_Load method and I am still having an issue.
    Also please replace
    item.addTo(CfdbOptionsMenu);
    with
    CfdbOptionsMenu.Items.Add(item);
  3. #3
    I am still receiving an error "The control with ID 'CenterContent_CfdbVer21' not found" after changing the code from:

    item.addTo(CfdbOptionsMenu);
    to

    CfdbOptionsMenu.Items.Add(item);
    Before the change I was receiving the error "The control with ID "CfdbVer21' not found"

    I read through the following link Issue when creating Menuitems dynamically
  4. #4
    Quote Originally Posted by cwolcott View Post
    I am still receiving an error "The control with ID 'CenterContent_CfdbVer21' not found"
    It should mean that the control with ID 'CenterContent_CfdbVer21' is not recreated during DirectEvent.

    What is the 'CenterContent_CfdbVer21' control? How is it created? Is it configured with DirectEvents?
  5. #5
    Based on the original post I create the menuItems dynamically in the Page_Load and have since remove the "if (!X.IsAjaxRequest) { }" test. So the controls are created evertime.

    protected void Page_Load(object sender, EventArgs e) {
        //if (!X.IsAjaxRequest)    {
           CFVDataContext dc = new CFVDataContext;
    
           // Retrieve all available versions that can be selected.
           var q = from c in dc.CfdbVersions
                      where c.IsActive == true
                      orderby c.Order descending
                      select c;
           // Create the menu items
           foreach (var c in q)
              {
              Ext.Net.MenuItems item = new Ext.Net.MenuItems() {
                 ID = "CfdbVer" + c.CfdbVer.ToString(),
                 Text = c.Description,
                 Icon = Icon.Database
              };
    
              item.DirectEvents.Click.Event += SelectCfdbVersion;
    
              Ext.Net.Parameter prmVer = new Ext.Net.Parameter() {
                 Name = "Version",
                 Value = c.CfdbVer.ToString(),
                 Mode = Parameter.Value
              }
             item.DirectEvents.Click.ExtraParams.Add(prmVer);
    
               Ext.Net.Parameter prmDesc = new Ext.Net.Parameter() {
                 Name = "Description",
                 Value = c.Description,
                 Mode = Parameter.Value
              }
             item.DirectEvents.Click.ExtraParams.Add(prmDesc);
    
             //item.addTo(CfdbOptionsMenu);
             CfdbOptionsMenu.Items.Add(item); 
            }
        //}
     }
    I assign each MenuItem with the ID = "CfdbVer" + c.CfdbVer.ToString().
    The CenterContent verbage is the ID of my ContentPlaceHolderID. This page has a MasterPage.

    The ID of the CfdbOptionsMenu that they are added to is "CfdbOptionsMenu".

    When I used item.addTo(CfdbOptionsMenu) instead of CfdbOptionsMenu.Items.Add(item) to add each menuItem the missing control was called "CfdbVer21" just like the ID I assigned to it.

    Any thoughts?
  6. #6
    Try to move recreation logic to Page_Init

    When I used item.addTo(CfdbOptionsMenu) instead of CfdbOptionsMenu.Items.Add(item) to add each menuItem the missing control was called "CfdbVer21" just like the ID I assigned to it.
    Use IDMode="Static" for controls or it's container
    Vladimir Shcheglov
    Sr. Developer
  7. #7
    Thanks, everything worked perfect. Please close the thread.

    Moved the creation of the controls into Page_Init and outside the test for !X.IsAjaxRequest and added IDMode="Static" to the parent control of the menuItems.

Similar Threads

  1. Replies: 0
    Last Post: Feb 06, 2012, 1:59 PM
  2. [CLOSED] Dynamic DirectEvents
    By albayrak in forum 1.x Premium Help
    Replies: 2
    Last Post: Mar 10, 2011, 9:12 AM
  3. [CLOSED] Dynamcally created Combox and its Dynamic Store
    By vali1993 in forum 1.x Premium Help
    Replies: 4
    Last Post: Jan 21, 2011, 4:10 PM
  4. Dynamic Menu with DirectEvents
    By Ganesh3.shirsath in forum 1.x Help
    Replies: 4
    Last Post: Oct 16, 2010, 6:01 PM
  5. Dynamic DirectEvents
    By Dominik in forum 1.x Help
    Replies: 3
    Last Post: Jul 30, 2010, 12:58 PM

Posting Permissions