PDA

View Full Version : [CLOSED] How to make MenuItem Clickable and call a Direct Method?



Fahd
Jan 18, 2013, 3:53 PM
Hi,
I am having trouble creating the "Click Event" on a MenuItem created dynamically from an XML file. The menuItems show up correctly on the screen but when I click on the menuItem, it is giving me the error message:
The control with ID 'id1f56fb29c2d1e820' not found



<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="MasterWithSusan.aspx.cs"
Inherits="MasterPageTest.MasterWithSusan" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<script runat="server">
[DirectMethod]
public string Items(Dictionary<string, string> parameters)
{
string tag = parameters["tag"];

List<Ext.Net.MenuItem> items = new List<Ext.Net.MenuItem>();

List<String> MenuList = CreateMenuItems(tag);
foreach (string menuitem in MenuList)
{
Ext.Net.MenuItem mi = new Ext.Net.MenuItem(menuitem) { Icon = Icon.ArrowRight, };
mi.DirectEvents.Click.Event += new ComponentDirectEvent.DirectEventHandler(mi_DirectC lick);
items.Add(mi);
}
return ComponentLoader.ToConfig(items);
}

public List<String> CreateMenuItems(string masterMenu)
{
List<String> menuItemElements = new List<String>();
XDocument doc = XDocument.Load(@"C:\DATA\Projects\Test\MasterPageTest\MasterPageTes t\NewMenu.xml");

if (doc.Root == null) return null;
var mainMenus =
doc.Root.Elements("MainMenu").Where(
m => ((string)m.Attribute("ID") == masterMenu)).
Select(m => new
{
ID = (string)m.Attribute("ID"),
MenuName = (string)m.Attribute("MenuName"),
MenuItems = m.Element("MenuItems").Elements("MenuItem").Select(menuItem => (string)menuItem.Attribute("ItemName"))
});
foreach (var mainMenu in mainMenus)
{
menuItemElements.AddRange(mainMenu.MenuItems);
}

return menuItemElements;

}

public void mi_DirectClick(object o, DirectEventArgs e)
{
Ext.Net.X.Redirect("Test.aspx");
}

</script>
</head>
<body>
<form id="Form1" runat="server">
<ext:ResourceManager ID="ResourceManager1" runat="server" />
<ext:Toolbar ID="Toolbar1" runat="server">
<Items>
<ext:Button ID="Button1" runat="server" Text="Schedule">
<Menu>
<ext:Menu ID="Menu1" runat="server" TagString="Schedule">
<Items>
<ext:MenuItem ID="MenuItem1" runat="server" IconCls="x-loading-indicator" Text="Loading..."
CanActivate="false" HideOnClick="false" />
</Items>
<Loader Mode="Component" DirectMethod="#{DirectMethods}.Items" RemoveAll="true">
<Params>
<ext:Parameter Name="tag" Value="this.tag" Mode="Raw" />
</Params>
</Loader>
</ext:Menu>
</Menu>
</ext:Button>
</Items>
</ext:Toolbar>
</form>
</body>
</html>



Below is the NewMenu.XML file:


<?xml version="1.0" encoding="utf-8" standalone="yes"?>

<Menu>

<MainMenu ID ="Schedule" MenuName="Schedules" Roles="Shipper" >
<MenuItems>
<MenuItem Id="1" ItemName="Trailer Schedule"/>
<MenuItem Id="2" ItemName="Custom Schedule"/>
</MenuItems>
</MainMenu>

</Menu>


5435

Thank you in advance for your help.

Baidaly
Jan 19, 2013, 3:34 AM
Hello!

In your case it's better to use DirectMethod, because you have to recreate dynamic controls, in your case MenuItems, on each request.

Some information you can read in this thread: http://forums.ext.net/showthread.php?12788-Issue-when-creating-Menuitems-dynamically