views:

16

answers:

0

I have a Menu control implemented on a ASPX page. I extended the MenuItem class so that when you create it you can pass in the command (initialized with its handler) so that when you click a specific MenuItem it automatically knows what event handler to go to. This allows me not to code a switch statement for the OnMenuItemClick logic.

This is esstentially how it is added (in the background it sets it via the extension method I mentioned earlier):

MenuManager.AddMenuItemCommand(menuItem, new Command(OnCommand));

This is the base class for the commands:

public abstract class BaseMenuCommand : IMenuCommand
{
    protected EventHandler CommandEventExecute;

    public BaseMenuCommand(EventHandler handler)
    {
        CommandEventExecute = handler;
    }

    #region IMenuCommand Members

    public void Execute(object sender, EventArgs e)
    {
        if (CommandEventExecute != null)
        {
            CommandEventExecute(sender, e);
        }
    }

    #endregion
}

So... when you click a MenuItem it goes to the menu's OnMenuItemClick event which then calls:

menu.SelectedItem.Execute();

This all works...SORT OF. Here is my real problem. When this is called all of the code executes just as you would expect. It goes all the way through the code to then OnCommand event handler. However, the Page does not get updated after the code is run. I cannot figure out why.

Everything seems to trigger logically. What is weird is that if instead of calling the Execute() method on the menu.SelectedItem from within the OnMenuItemClick event I simply call the OnCommand method... it all works perfectly...

I cannot figure out why! Please help?

My only guess thus far is that it might be occurring outside of the Page life cycle somehow.

Edit:

I think this will more clearly show you what the problem is:

protected virtual void ApplicationMenu_MenuItemClick(object sender, MenuEventArgs e)
    {
        Menu menu = sender as Menu;

        if (menu == null)
            return;

        if (menu.SelectedItem == null)
            return;

        menu.SelectedItem.Execute(); //This does not work

        OnCommand(sender, e); //This does work
    }

    protected virtual void OnCommand(object sender, EventArgs e)
    {
        //implementation of some sort
    }

With both lines of code they get to the OnCommand method. One works for updating the Page the other does not.