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!).



4 comments:
Thank you very much!!!
This code working fine...
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/
Great tip! Save a lot of time! Thanks!
Maybe I should also ask, why does this work? I don't really understand what this does...
Thanks!
Post a Comment