Home - Forums-.NET - FlyTreeView (ASP.NET) - Context menu - looks like event doesn't fire

FlyTreeView (ASP.NET)

Technical support and KB related to the FlyTreeView control

This forum related to following products: FlyTreeView for ASP.NET

Context menu - looks like event doesn't fire
Link Posted: 22-Mar-2007 12:16
Hello,
I've got trouble to get the context menu work. The javascript-stuff works fine, but it like to go one step further and refer back to server code. I tried it like that:
...
FlyMenuItem myItem = new FlyMenuItem();
myItem.Text = \"Test Menu Command\";
myItem.CommandName = \"menu_Command\";
myItem.AutoPostBack = true;
mTest.Items.Add(myItem);
mTest.Command += new FlyContextMenuCommandEventHandler(menu_Command);
this.Controls.Add(mTest);
...

void menu_Command(object sender, FlyContextMenuCommandEventArgs e)
{
throw new Exception(\"The method or operation is not implemented.\");
}

I never get this exception, in debug mode I don't get to the stop there.
Is the code correct?

Best regards,
rawaho
Link Posted: 22-Mar-2007 12:47
[quote="rawaho"]Hello, this.Controls.Add(mTest);
What is this? Is it page or usercontrol? If page, then it could cause javascript problems. Otherwise your sample is ok. Here is what I have completely ok: [code] <%@ Register Assembly="NineRays.WebControls.FlyTreeView" Namespace="NineRays.WebControls" TagPrefix="NineRays" %> protected override void OnInit(EventArgs e) { base.OnInit(e); FlyContextMenu myMenu = new FlyContextMenu(); myMenu.ID = "myMenu"; FlyMenuItem menuItem = new FlyMenuItem("click me", "mycommand"); menuItem.AutoPostBack = true; myMenu.Items.Add(menuItem); myMenu.Command += new FlyContextMenuCommandEventHandler(myMenu_Command); panel.Controls.Add(myMenu); } void myMenu_Command(object sender, FlyContextMenuCommandEventArgs e) { throw new Exception("The method or operation is not implemented."); } Untitled Page
[/code]
Link Posted: 23-Mar-2007 03:12
Hello Evgeny,
thanks again for your outstanding support, your example solved my issue - I changed the call to my CreateMenu-function from OnPreRender to OnInit and now it works fine.
To answer your question to this: The tree is contained in a webpart, so this refers to the webpart.
Some other thing: Did I overlook some examples? Your demo is fine, but I didn't find the example as you give it here.
Best regards,
rawaho
Link Posted: 23-Mar-2007 04:04
This example was created specially for your case.