PDA

View Full Version : [CLOSED] Dynamic created MenuItems and directEvents



cwolcott
Jun 13, 2012, 7:28 PM
Releated to the following topic Disable a MenuItem when button selected (http://forums.ext.net/showthread.php?19514-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 (http://forums.ext.net/showthread.php?10984-CLOSED-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.

Daniil
Jun 13, 2012, 9:07 PM
Hi,



I found the following thread Gridpanel Directevent in code behind (http://forums.ext.net/showthread.php?10984-CLOSED-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);

cwolcott
Jun 14, 2012, 2:49 PM
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 (http://forums.ext.net/showthread.php?12788-Issue-when-creating-Menuitems-dynamically)

Daniil
Jun 14, 2012, 3:00 PM
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?

cwolcott
Jun 14, 2012, 3:29 PM
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?

Vladimir
Jun 14, 2012, 3:36 PM
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

cwolcott
Jun 14, 2012, 5:04 PM
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.