Friday, 5 September 2008

Getting ASP.NET menus to work with Chrome

The asp.net menu does a check to see if the browser the client uses can support JavaScript or not. But the check is not a very good one!

You can force the menu to work by overwrite the Page_PreInit method on the page and telling the page that the client target is a modern “uplevel” browser:-

protected void Page_PreInit(object sender, EventArgs e) 
{
if (Page.Request.ServerVariables["http_user_agent"].ToLower().Contains("safari"))
{
Page.ClientTarget = "uplevel";
}
}



Please note that you have to do this in the page class file, and not in the master page class file. Obviously this means you have to do it for every page – which is not ideal.



To get round this limitation simply make a class which inherits from System.Web.UI.Page, and change all your pages to inherit from this class instead (a find and replace is ideal here!).

12 comments:

Selvaganapathy said...

Thank you very much!!!

This code working fine...

matware said...

Instead of updating all your code, just add a browser caps section to your web.config to support Chrome (and all the millions of other browsers that will break).
Check out this link for details.
http://owenbrady.net/browsercaps/

jwright said...

Great tip! Save a lot of time! Thanks!

jwright said...

Maybe I should also ask, why does this work? I don't really understand what this does...

Thanks!

d347hm4n said...

Thanks alot for this, it's a little annoying that you have to implement it on all of the pages that inherit this control instead of doing it in the master page. C'est la vie.

Joshua Smith said...

Thank you for talking about useful subject. It needs to know that mobile apps development could help in your industry by installing custom development software solutions. Also you may turn your attention on outsourced enterprise content management software.

Joshua Smith said...

That is nice article. Let me mention about home owners insurance cost that are from home insurance providers. Compare online quotes on homeowners insurance.

Joshua Smith said...

Thank you for writing this useful review. You have great chance to clarify casino affiliate programs. The most common casino affiliate programs such as 32 Red affiliates and great poker rooms such as redbet.

Joshua Smith said...

I'm glad to read about this. Here we are willing to share with cheap insurance that is provided by common auto insurance companies. You may save on cheap homeowners insurance rates which allow customers to obtain cheap affordable policy.

Joshua Smith said...

I'm glad to read about this. Let me share with insurance instant that is provided by common home and auto insurance companies. You may save on auto instant insurance quotes which allow you to get cheap affordable policy.

Nisha said...

hello sir, what will be code for VB.net. Thanks

John Peter said...

Great Article

ASP.NET Training
Dot Net Training in Chennai