This project is read-only.
ActiveMenu a simple derivative component to replace the ASP.Net Menu component in found in Visual Studio.

I was in the middle of presenting a notification application to a group of directors and executives. Suddenly, one of the directors says the menu is NOT displaying correctly in Internet Explorer 8... wtf Microsoft, can't you make sure your shit works?

I investigated! Seems everybody made all sort of work a rounds for IE8. Modified their web pages; tell IE8 to run in IE7 compatibility mode, blah blah blah. As per the normal in our society treat the sympton not the problem. Just make the control render properly in a browser that support CSS and java script. As a precaution I checked to see if the menu worked in other browsers and I was astounded how bad the compatibility was... I put in the fixes to make the menu render properly in most java script compliant browsers as well as a fix to make the menu item clickable across the whole item surface, not just the text of the menu item.

Good luck... I published this coded in case other developers wish to make modifications or improvements. Please be kind enough to drop me a line, if you make an impovement.

Thanks

-James


Source code for C#:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ComponentModel;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.Adapters;

// change to your own custom component namespace.
namespace MoonDust
{
    

    [ToolboxData("<asp:ActiveMenu runat=server></asp:ActiveMenu>")]
    public class ActiveMenu : Menu
    {
        // the menu works - just needs tweaking.
        public ActiveMenu(): base()
        {
            // do nothing in the constructor.
        }

        private const string ClassSupportScript = "<style type=\"text/css\">.ActiveMenuStyle{z-index: 100;}.ActiveMenuItemStyle a{width:100%;display:block;}</style>";

        protected override void OnPreRender(EventArgs e)
        {
            //override the rendering of the css class if the cssclass is not present
            //if cssclass is present lets hope they set the z-index in the their style sheet
            if (DynamicMenuStyle.CssClass == "")
                DynamicMenuStyle.CssClass = "ActiveMenuStyle";

            if (DynamicMenuItemStyle.CssClass == "")
                DynamicMenuItemStyle.CssClass = "ActiveMenuItemStyle";

            if (StaticMenuStyle.CssClass == "")
                StaticMenuStyle.CssClass = "ActiveMenuStyle";

            if (StaticMenuItemStyle.CssClass == "")
                StaticMenuItemStyle.CssClass = "ActiveMenuItemStyle";

            // call the base style render
            base.OnPreRender(e);

            // write this style tag only once on the page
            this.Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "ActiveMenuStyleBlock", ClassSupportScript);

        }

        

        protected override System.Web.UI.Adapters.ControlAdapter ResolveAdapter()
        {
            // just assume the browser is modern. resolves firefox, crome, safari 
            // not the best idea for old browsers - tough cookies 
            return null;
        }

    }
}

Last edited Apr 18, 2009 at 4:34 PM by joenetking, version 7