Mark Hildreth's Blog

asp:Menu in IE8

I've been using IE8 Beta 2 since sometime in August. As soon as I had downloaded it, I raced to my sites to see if there were any issues caused by the new browser's strict adherence to standards. I'm pretty conservative when it comes to my page and control design, so I didn't expect too many issues. Unfortunately, most of our sites rely on the asp:Menu control to provide navigation. The first thing I noticed was that I could no longer see the Dynamic menu items when hovering over the menu. This is a pretty serious problem because that's the main way users navigate around the site. I did some basic googling and searching on the ASP.NET Forums, and there were quite a number of people with the same problem, but there didn't seem to be an obvious solution.

Needless to say, ever since then I've been eagerly anticipating the IE8 release candidate in hopes that this issue would just fix itself. Well, the release candidate just hit yesterday and it turns out the issue with the ASP.NET Menu control wasn't resolved. I'm sure the breakage was the result of a change to make the browser more standards compliant. Of course that's a good thing, but it's still annoying that I will have to fix old code to account for new browser changes.

 As it turns out, the fix is really straight forward. I'd like to thank the original poster and the folks at Microsoft Connect for posting enough information on this post to get me started. When the menu is rendered, a script resource is included on the page that contains a function called PopOut_Show. The function detects and sets the z-index property of the panel containing the dynamic menu items. The problem is the value for the z-index is calculated differently depending only on whether or not the browser is IE, not which version of IE. Thus, the z-index calculations for IE were assuming that the element.currentStyle.zIndex property would return a numeric value, but in IE8, unless the z-index for these elements has been specified (in a stylesheet or somewhere), the return value is "auto".

I had originally toyed around with using script to adjust the z-index values. That involved swapping in a new PopOut_Show function to append additional logic to account the "auto" value. After I took a second look at it, I realized the same thing could be done using only CSS which seemed like a much better solution. It turned out that all that was really needed was to create or modify a CSS class that includes a z-index value of at least 1, then assign the class to the Menu's DynamicMenuStyle property.  The CSS class would look something like this:

.adjustedZIndex {
    z-index: 1;
}

And the resulting Menu looks something like this:

<asp:Menu ID="Menu1" runat="server">
    <DynamicMenuStyle CssClass="adjustedZIndex" />
</asp:Menu>

You may have to set your z-index to be something higher (for example, if your menu was contained in an element that already had a z-index greater than 1), but this worked for me. I hope this is a help to those who have run into the same issue. Good luck with IE8 - My experience so far has been great!

 If you're interested in the script solution, just let me know and I'll post it.

Posted: Jan 26 2009, 09:57 PM by mhildreth | with 47 comment(s)
Filed under: , , ,

Comments

Scott Galloway said:

Good post...you may be happy to hear that we will be fixing a few things in the markup for the Menu control in ASP.NET 4.0, these won't unfortunately make Beta 1.

# January 26, 2009 10:58 PM

John Walker said:

@Scott - So, is this the recommended solution in the interim? Can browsercaps be used instead?

# January 27, 2009 3:36 AM

Maik’s Blog » Blog Archive » ASP:Menu in IE8 said:

Pingback from  Maik&#8217;s Blog  &raquo; Blog Archive   &raquo; ASP:Menu in IE8

# February 10, 2009 4:32 AM

Shay said:

Considering the fact that not many has migrated to asp.net 3.5 yet, and most sites using asp.net 2.0, what good will it do to them asp.net 4.0 and that also will be beta?

# March 26, 2009 1:23 PM

Pop Out Menu IE8 | keyongtech said:

Pingback from  Pop Out Menu IE8 | keyongtech

# March 28, 2009 10:07 PM

Oran Bodner said:

Actually this affected more my http://hop2home.com

Anyway, the patch didn't work, but your CSS patch worked like magic - may thanks!

Tell me - I'm tired of doing a workaround so that datagrids/gridviews don't scroll their headers - do you know if they're ever going to come out with one where you can specify something like "fixed header - do NOT scroll")?

ojbodner@hotmail.com

# April 3, 2009 6:50 AM

» IE8 - What you need to know :: CSS, JavaScript and XHTML Explained said:

Pingback from  &raquo; IE8  - What you need to know :: CSS, JavaScript and XHTML Explained

# April 23, 2009 2:50 PM

rizasirman2 said:

It works GR8!.. Thanks

# April 28, 2009 4:58 AM

Mnvs said:

Fix works for me.

GREAT!

# April 28, 2009 12:51 PM

Daniel said:

css fix is not working on my site.

# May 1, 2009 8:01 AM

NJ said:

Excellent tip, thanks. Saved me a lot of time.

# May 4, 2009 4:09 AM

W Forrest said:

I have two websites down and i’am on programmer can you clarify where on the master page and how i apply your fix.

bill

e mail bill@speyvideo.com

www.speyvideo.net

www.speyvideo.com

# May 7, 2009 11:05 AM

KPACABA said:

Worked like a charm, thanks much!

# May 8, 2009 2:00 PM

Juan Carlos said:

Thanks so much. I was afraid that i was going to have to remake the menu as html/css menu, though it still might be a good idea.

# May 20, 2009 3:43 PM

Aaron said:

Great tip! Saved me a headache, thanks!

# May 27, 2009 12:09 PM

Timothy Neville said:

LOVE YOU! Thanks so much.

# May 27, 2009 4:16 PM

alkutin said:

I have fixed this error on my site too.

I "set z-order: 8" for ASP:Menu DynamicMenu style and it works now!

# June 2, 2009 12:10 PM

yubi said:

my problem is the spacing show up between </td><td>. It happened after install IE7 to IE8.

It still the same after I applied your solution.

Pls give me some advice. Thx

# June 17, 2009 1:40 AM

ASP.Net Menu and ie8 problems | Sudden Gust of Gravity said:

Pingback from  ASP.Net Menu and ie8 problems | Sudden Gust of Gravity

# June 18, 2009 10:07 PM

nova said:

Only changed one sub menu item, i can't see the other sub menu items

# June 19, 2009 10:19 AM

cbm said:

Perfect! Thanks! You are awesome mhildreth!

# June 22, 2009 6:28 AM

Keith Holme said:

Great fix. Thanks.

# July 5, 2009 6:31 AM

Mike Samuels said:

I second the "thank you"

# July 8, 2009 11:04 AM

milia1000 said:

On Safari 3.2.1 and Google Chrome 2... :-(

# July 9, 2009 11:16 AM

milia1000 said:

What I would say on my last comment was that if you try to correct the z-index to solve IE8 menu problem, then the asp.net menu on Safari and Google Chrome stop work.

My solution:

- FOR IE8: <meta http-equiv="X-UA-Compatible" content="IE=EmulateIE7" /> on masterpage (new IE8 and a simple menu doesn't work?! ¿? )

- FOR SAFARI/GOOGLE see weblogs.asp.net/.../how-do-i-overcome-the-dreaded-safari-asp-net-menu-conundrum.aspx

Thanks, hope that helps someone.

# July 9, 2009 12:51 PM

Asp.Net Menu and ie8 Problems « Sudden Gust Of Gravity said:

Pingback from  Asp.Net Menu and ie8 Problems &laquo; Sudden Gust Of Gravity

# July 9, 2009 1:58 PM

Subash Nair said:

very good fix. thanks

# July 12, 2009 1:21 AM

sarah said:

Such a simple clean fix, thanks so much!

# July 13, 2009 8:01 AM

Tim Randall said:

An elegant fix. thanks very much.

# July 22, 2009 3:49 AM

Felipe said:

Hi man, thanks for this 'simple' solution, it help me a lot and save me to much time.

# July 29, 2009 7:24 PM

balle3201 said:

Thx alot, mate :-)

Worked like a charm!

# August 11, 2009 4:42 AM

leila said:

it dosent work for my website. i am tired.

# August 16, 2009 3:49 AM

Kram said:

Thanks a bunch.  Worked for me.    

# August 23, 2009 6:09 PM

mhariri said:

Great fix for Firefox But I am not sure why after I added the code only the first item on the dynamic menu show up in IE8!! I tried Z-Index:1 and 999 without any luck. Any ideas?

# August 23, 2009 8:48 PM

Michael Doscher said:

Just an FYI this will not work with Iframes on the page. the entire menu is then removed

# August 24, 2009 7:22 PM

Rm.Ramanathan (New Delhi,India) said:

Thanks. It works great. Keep it up.

# August 30, 2009 4:31 AM

dupls said:

I'm getting a blank drop down menu. This Css didn't solve the problem.

Any other ideas?

# September 2, 2009 11:58 AM

Gav said:

Great - Simple fix, just got the IE8 Dev toolbar to look at the drop down, saw z-index set to 'auto' then edited number till links were visible!

Great stuff - saved me alot of head-scratching...

# September 8, 2009 4:56 AM

Dharmesh Patel said:

Thanks mhildreth

i was tried more than 2 days but didn't get solution

Now it's work greate

# September 9, 2009 10:41 AM

James Hamilton said:

Thanks mhildreth, I didn't know about this problem until a user of my site pointed it out to me yesterday.  The CSS class solution appears to work for me.  As a complete newb to writing a site in the .Net framework, these blogs are a real help to me.

Thanks again.

# September 13, 2009 7:50 AM

Christian Donner said:

From W2Schools:

z-index only works on positioned elements (position:absolute, position:relative, or position:fixed).

The dynamic menu is a table, and it is not positioned. Anyway, the menu works for me in IE8. I am having this problem with .Net 3.5 in compatibility mode, not in standards mode. The dyanmic menu pops up, but is behind a Span that is is front of it. Using z-index on either element has no effect.

See www.heeroz.com/overlap.png

# September 17, 2009 10:51 PM

Greg Bell said:

Thanks, works well!

# October 11, 2009 10:38 PM

Robert said:

Thanks very much for the CSS "fix".

It is very simple and it works perfectly for me.

# October 13, 2009 10:46 AM

Chandra said:

Thanks a lot... saved my web site. Works great.

# October 14, 2009 12:16 PM

shubelal said:

This is fabulous work. its save time alot

Thanks you so much

# October 27, 2009 10:13 AM

gummadi said:

what you suggested i tried but its not working please if u come accross like please give me shout

my mail id gummadi.ram@gmail.com

# November 4, 2009 6:31 AM

DAVETİYE said:

güzel davetiye örnekleri, davetiye modelleri, düğün davetiyeleri

# November 5, 2009 7:13 AM
Leave a Comment

(required) 

(required) 

(optional)

(required)