Internet Handholding posted on August 16, 2010 20:36

The Asp.Net menu control does not display drop down menus on Apple in Safari browser and may have problems on Chrome and other browsers.
The two manifestations I have seen are no drop down menus in IE8 and the drop down under my about page looks like this in Safari and maybe Chrome.
About EXPAND About
The other problem I saw was a partial outline of the drop down menu, but no menu choices. When I clicked the compatibility button, the menus showed up.
The reason this happens is Asp.net tries to adjust for the browser capabilities. One of the behaviors I came across was Asp.net replacing Div tags with Table tags when downgrading for browser level.
The first problem is how to test this if you do not have an Apple computer or downlevel browser. I put this line of code in my Page_Preinit event and that simulated the EXPAND problem at least.
protected virtual void Page_Preinit(object sender, EventArgs e)
{
this.Page.ClientTarget = "downlevel";
}
Found a couple of proposed solutions online. One involved setting the ClientTarget to "uplevel", which idea I used to recreate the problem for testing in the code above.
I already had a wrapper for the Asp.net menu control and was tempted to put the fix there.
There were a number of suggestions on where to put the code. This one seemed to work well, but I did not like the idea of calling this extra AddedControl every time a control was added to the page. It is probably no big deal, but I am picky that way. I do not mind an isolated kludge, but I do not like general ones.
This one put the "uplevel" in the Page_Preinit event and I liked that better since it is only called once per page and that is what I did.
One solution checked for "Safari" and the other for "AppleWebKit". I figured it would be safer to check for both.
protected virtual void Page_Preinit(object sender, EventArgs e)
{
if (HttpContext.Current.Request.UserAgent != null)
&&
(
(HttpContext.Current.Request.UserAgent.IndexOf("AppleWebKit"
, StringComparison.CurrentCultureIgnoreCase) > -1)
||
HttpContext.Current.Request.UserAgent.IndexOf("Safari"
, StringComparison.CurrentCultureIgnoreCase) > -1
)
this.Page.ClientTarget = "uplevel";
}
Of course, that is not how I actually coded it. I put the code in its own method so I could call it from anywhere.
By Andrew Weitzen, Bronze Inc. (c) 2010
Bronze is the publisher of several online Internet journals including: InternetHandholding.com, DomainNames.gs, DotNetNuke.bz, Programmer.bz, Software.vg, WebHosting.vg