解决ASP.NET下的MENU控件在IE8中不显示的问题

原地址:http://blogs.msdn.com/giorgio/archive/2009/02/01/asp-net-menu-and-ie8-rendering-white-issue.aspx

ASP.NET Menu and IE8 rendering white issue

If you are using the ASP.NET Menu control, you might encounter under certain circumstances an issue where the menu appears as a white box in IE8 Standards Mode.

image

What IE8 is doing IS correct (by design), in the sense that in Standards mode IE8 is following the standards. Specifically, (element).currentStyle.zIndex returns "auto" in Standards mode when zindex has not been set. The ASP.NET Menu control assumes a different value.

I’d like to suggest a few possible workarounds to solve quickly the issue (note, you can use either one of them, depending on your scenario):

  1. Overriding the z-index property
  2. Using CSS Friendly Control Adapters
  3. Adding the IE7 META tag to the website

1 – Overriding the z-index property

You can manually set the z-index property of the Menu items using the DynamicMenuStyle property of the asp:Menu control (note lines 9-14 and 20). Full source code is:

   1: <head runat="server">
   2:     <title></title>
   3:     <style type="text/css">
   4:         body
   5:         {
   6:             background-color: Silver;
   7:         }
   8:     </style>
   9:     <style type="text/css">
  10:         .IE8Fix
  11:         {
  12:             z-index: 100;
  13:         }
  14:     </style>
  15: </head>
  16: <body>
  17:     <form id="form1" runat="server">
  18:     <div>
  19:         <asp:Menu ID="Menu1" runat="server" DataSourceID="SiteMapDataSource1">
  20:             <DynamicMenuStyle CssClass="IE8Fix" />
  21:         </asp:Menu>
  22:         <asp:SiteMapDataSource ID="SiteMapDataSource1" runat="server" />
  23:     </div>
  24:     </form>
  25: </body>

This solution is the least intrusive, but it require a page-by-page update (unless your menu is a Master Page).

2 – Using CSS Friendly Control Adapters

Thanks to Tim for this solution. In order to add the CSS Friendly adapter to your project, you will need to:

  1. Download CSSFriendly.dll and CSSFriendlyAdapters.browser from here.
  2. Inside your project, add a reference to CSSFriendly.dll.
  3. Add the special folder App_Browsers to your project, and copy the file CSSFriendlyAdapters.browser.

The CSS Friendly Control Adapters will render all the listed controls (Menu, TreeView, DetailsView, …) using CSS and HTML standards.

3 – Add the IE7 META tag to the project

By default, Windows Internet Explorer 8 will attempt to display content using its most standards-compliant mode, the IE8 Standards mode. However you can still switch to the IE7 Standards mode adding a particular META TAG to the head of the page:

   1: <html xmlns="http://www.w3.org/1999/xhtml">
   2: <head runat="server">
   3:     <meta http-equiv="X-UA-Compatible" content="IE=EmulateIE7" />
   4:     
   5:     <title>IE8 ASP.NET Fix</title>
   6: </head>
   7: <body>

Using the tag, the website in IE8 will look and work in the same way as it does in IE7.

You can do a “live test” of this feature without the need to modify the page, using the new IE8 Developer Toolbar (press F12 to open the toolbar, and switch the Document Mode to IE7 Standards).

image

Note that you can set up the META tag at page level, at web.config level, or in IIS, or in Apache, …

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值