posts - 31, comments - 85, trackbacks - 0

My Links

News

Archives

Post Categories

asp:Menu rendering problems in IE8, Safari and Chrome

I was caught off-gaurd today when a user of one my applications reported that the asp:Menu was not rendering properly in her IE browser. I checked the version and it was IE8. I changed the application to compatibility view and the menu rendered just fine.

Since I cannot tell each and every user to view the app in compatibility view when in IE8, i started digging for solutions. It looked like a z-index problem to start with. The problem was that since the new IE8 is moving closer to standards, the z-index value was set to "auto" when not specified. I tried changing it something bigger than its container's z-index value woo-hoo...it worked.

I just added this line in the CSS class definition:

z-index : 100; /* Setting z-index because of an IE8 bug */

Since it is a bug, there are some hotfixes available from MS here.

This problem prompted me to look for rendering in Chrome and Safari also.

The asp:Menu control looks horrible in Chrome. There are no popups, just plain static text. I stumbled upon this thread which discusses this problem. I did not use the method posted in that thread, instead, I used a solution posted by user Mark Perkins which to me looked like the simplest and cleanest solution. Here is what he posted:

Put this piece of code in your Master page code file:

// Adding this override so that the asp:Menu control renders properly in Safari and Chrome
 
    protected override void AddedControl(Control control, int index)
    {
        if (Request.ServerVariables["http_user_agent"].IndexOf("Safari", StringComparison.CurrentCultureIgnoreCase) != -1)
        {
            this.Page.ClientTarget = "uplevel";
        }
        base.AddedControl(control, index);
    }

 

  • Share This Post:
  • Share on Twitter
  • Share on Facebook
  • Share on Technorati

Print | posted on Wednesday, July 08, 2009 9:00 AM | Filed Under [ ASP.NET ]

Feedback

Gravatar

# re: asp:Menu rendering problems in IE8, Safari and Chrome

Thanks! This piece of code finally worked to bring visibility to my menu! I had to add it to my master page code-behind file, like so:

public partial class App_Components_default : System.Web.UI.MasterPage
{
protected override void AddedControl(Control control, int index)
{
if (Request.ServerVariables["http_user_agent"].IndexOf("Safari", StringComparison.CurrentCultureIgnoreCase) != -1)
{
this.Page.ClientTarget = "uplevel";
}
base.AddedControl(control, index);
}
protected void Page_Load(object sender, EventArgs e)
{

}
}
10/2/2009 3:35 PM | Todd Huotari
Gravatar

# re: asp:Menu rendering problems in IE8, Safari and Chrome

Hi, This is a great post, its help me out great. THIS IS TRUSTED ONE POST. Recommended.....
11/2/2009 6:00 PM | Saad
Gravatar

# re: asp:Menu rendering problems in IE8, Safari and Chrome

You are my saviour! Thanks...
11/5/2009 3:20 PM | leonard
Gravatar

# re: asp:Menu rendering problems in IE8, Safari and Chrome

How do you add the code to the "CSS class definition." Sorry I am new to all of this!
11/6/2009 5:32 PM | DBounlom
Gravatar

# re: asp:Menu rendering problems in IE8, Safari and Chrome


*DBounlom
the code is for when you are using asp.net. You can put in the code behind file.
11/6/2009 5:56 PM | Max
Gravatar

# re: asp:Menu rendering problems in IE8, Safari and Chrome

Super...It works. I had same problem. I used this piece of code in the master page.
if (Request.UserAgent.IndexOf("AppleWebKit") > 0)
{
Request.Browser.Adapters.Clear();
}
But its not working for the first time it loads. I tried the above code. Now its Working. Great post.
2/22/2010 4:51 AM | Nagasai
Gravatar

# re: asp:Menu rendering problems in IE8, Safari and Chrome

Thanks, i find for this solve for 1 day, but i found this page and can solve my problem.


Many Thanks.
3/8/2010 10:08 PM | Kue
Gravatar

# re: asp:Menu rendering problems in IE8, Safari and Chrome

Great Post

It works like a charm
3/11/2010 4:02 AM | vinita
Gravatar

# re: asp:Menu rendering problems in IE8, Safari and Chrome

Perfect !! I added this to my masterpage and everything worked like a charm. Thanks :-)
3/14/2010 8:36 PM | Jaden
Gravatar

# re: asp:Menu rendering problems in IE8, Safari and Chrome

I had the same rendering problem which I fixed up this way. I found
text menu and much more amazing controls at http://www.obout.com
these controls works on every internet navigator.
3/27/2010 2:12 AM | Ulsenio
Gravatar

# re: asp:Menu rendering problems in IE8, Safari and Chrome

Perfect !! I added this to my masterpage and everything worked like a charm. Thanks :-). Problem solved within one minute!!!!
3/27/2010 2:31 PM | Peter Winterberg
Gravatar

# re: asp:Menu rendering problems in IE8, Safari and Chrome

i tried the same code as Nagasai (above), which is all over the web, and it wasn't working for me either; it was very inconsistent.

your code has not failed once, from the first reload.

thank you.
7/1/2010 8:34 AM | wazz
Gravatar

# re: asp:Menu rendering problems in IE8, Safari and Chrome

Thanks a lot. That solved my problem!
7/29/2010 7:03 AM | Aurelio
Gravatar

# re: asp:Menu rendering problems in IE8, Safari and Chrome

Thanks. It works perfectly for my new project.
7/29/2010 11:49 AM | Patrick
Gravatar

# re: asp:Menu rendering problems in IE8, Safari and Chrome

Thanks you very much,I'm from Uruguay and I was loooking for this error and in one day I could find it. My problem was about a menu which in the rendering the HTML code generated change according the browser.
Again thanks, you save my life haha.

2/18/2011 8:44 AM | Sergio
Gravatar

# re: asp:Menu rendering problems in IE8, Safari and Chrome

Glad it helped!
2/18/2011 8:54 AM | Max
Gravatar

# re: asp:Menu rendering problems in IE8, Safari and Chrome

Does Not seem to help. Here is my code in the master page. Any Ideas?

Partial Public Class App_Components_default
Inherits System.Web.UI.MasterPage
Protected Overrides Sub AddedControl(ByVal control As Control, ByVal index As Integer)
If Request.ServerVariables("http_user_agent").IndexOf("Safari", StringComparison.CurrentCultureIgnoreCase) <> -1 Then
Me.Page.ClientTarget = "uplevel"
End If
MyBase.AddedControl(control, index)
End Sub
Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)

End Sub
End Class


Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
'If Request.UserAgent.IndexOf("AppleWebKit") > 0 Then
' Request.Browser.Adapters.Clear()
'End If
'If Request.UserAgent IsNot Nothing AndAlso (Request.UserAgent.IndexOf("AppleWebKit") > -1) Then
' Request.Browser.Adapters.Clear()
'End If


End Sub
4/24/2011 9:30 AM | DWb
Gravatar

# re: asp:Menu rendering problems in IE8, Safari and Chrome

Superb, i have used this solution in my project
12/2/2011 5:44 AM | Ramakrishnan
Post A Comment
Title:
Name:
Email:
Website:
Comment:
Verification:
 
 

Powered by: