Mar 15 2006

MasterPages and Browser Detection

Category: ASP.NET 2.0 - GeneralBil@l @ 13:38

A very nice feature of MasterPages in ASP.NET 2.0 is the ability of the ASPX page to detect the browser and render a specific MasterPage for the specific browser.

How is that done? As follows:

<%@ Page Language="C#" Mozilla:MasterPageFile="MozillaMasterPage.master" ie:MasterPageFile="IEMasterPage.master" ... %>

As you can see, we have added two properties to the page directive, which says, when the browser is of the Mozilla family like "FireFox", make use of the MozillaMasterPage.master file, and when the browser is IE, make use of the IEMasterPage.master file.

To get a list of all the browsers you can handle, go to:

{Drive Letter}:/[WINDOWS,WINNT]/Microsoft.NET\Framework\v2.0.50727\CONFIG\Browsers

There you can have the list of all the browsers.

The same trick is applied to Themes. For example you can apply a browser theme as:

Hope that helps,



Comments are closed