Click here to Skip to main content
Click here to Skip to main content

ASP.NET menu control issue in Chrome and Safari

By , 26 Jul 2012
 

INTRODUCTION

While using ASP.NET menu control at that time Safari as well as Chrome is not render that control properly. That’s the reason, why mouse over is not work properly in Chrome and Safari with ASP.NET menu control as shown in below images. 


Safari
Chrome

While it's working perfectly with Mozilla Firefox and IE


IE9
Mozilla Firefox

SOLUTIONS

As you can see the look and feel of the main menu is different. Submenu does not show up.So what is the solution for this. I search over Google and found these 3 solutions working perfectly.

Method 1

  • 1) Go to Solution Explorer in Visual Studio and add “ASP.NET Folder” named “APP_Broswers”.
  • 2) Add new item “Browser File” to this special folder and name it “safari.browser” for both browser Chrome as well as Safari.
  • 3) Now Delete all per-added data from safari.browser file.
  • 4) Now add the following tags to that browser file.
  • <browsers> 
        <browser refID="safari1plus"> 
            <controlAdapters> 
              <adapter controlType="System.Web.UI.WebControls.Menu" adapterType="" /> 
            </controlAdapters> 
        </browser> 
    </browsers>
    
  • 5) Now only you need is to save that file. 

Method 2

The other solution is using Server side code. For fixing bug we need to write this two line of code to each and every Page's Page_PreInit event, Or if MasterPage file is used then no need to add this lines to each and every page, just copy and paste this lines to Only MasterPage's Page_PreInit event. This code is working for both Safari as well as Chrome.

protected void Page_PreInit(object sender, EventArgs e)
{
    if(Request.ServerVariables["http_user_agent"].IndexOf("Safari",StringComparison.CurrentCultureIgnoreCase) != -1)
    {
        Page.ClientTarget = "uplevel";
    }
}

OR Use this alternate code

protected void Page_PreInit(object sender, EventArgs e)
{
  if (Request.UserAgent.Contains("AppleWebKit")) 
     Request.Browser.Adapters.Clear();
}

After applying any of these changes ASP.NET menu is working properly in all browser like Mozilla Firefox,IE,Safari and Chrome.


Chrome
Safari

Enjoy the trick!!!

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

About the Author

Tejas Vaishnav
Software Developer
India India
Member
No Biography provided

Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
Hint: For improved responsiveness ensure Javascript is enabled and choose 'Normal' from the Layout dropdown and hit 'Update'.
You must Sign In to use this message board.
Search this forum  
    Spacing  Noise  Layout  Per page   
GeneralMy vote of 5memberN10K14 Mar '13 - 23:00 
QuestionConext menumemberMember 812804019 Dec '12 - 19:34 
Questionthrown error..memberravi teja .k18 Dec '12 - 4:38 
AnswerRe: thrown error..memberTejas Vaishnav18 Dec '12 - 22:24 
GeneralMy vote of 4memberRajendra Bhandari11 Dec '12 - 23:16 
GeneralRe: My vote of 4memberTejas Vaishnav12 Dec '12 - 22:17 
GeneralMy vote of 5memberVijaychauhan080616 Nov '12 - 19:22 
GeneralRe: My vote of 5memberTejas Vaishnav19 Nov '12 - 22:45 
GeneralNon-intuitivemembercallcopse9 Nov '12 - 1:23 
GeneralRe: Non-intuitivememberTejas Vaishnav19 Nov '12 - 22:45 
GeneralMy vote of 5memberAbdul Quader Mamun13 Aug '12 - 17:07 
GeneralRe: My vote of 5memberTejas_Vaishnav16 Aug '12 - 0:06 
GeneralRe: My vote of 5memberAbdul Quader Mamun16 Aug '12 - 0:46 
GeneralRe: My vote of 5memberAbdul Quader Mamun16 Aug '12 - 0:46 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Permalink | Advertise | Privacy | Mobile
Web02 | 2.6.130516.1 | Last Updated 27 Jul 2012
Article Copyright 2012 by Tejas Vaishnav
Everything else Copyright © CodeProject, 1999-2013
Terms of Use
Layout: fixed | fluid