Question

MVC has a dll you can reference in your project called "system.web.webpages" and you use this to perform adaptive rendering inside your "application_start" method of the global.asax file like below:

DisplayModeProvider.Instance.Modes.Insert(0, new DefaultDisplayMode("iPhone")
            {
                ContextCondition = (context => context.GetOverriddenUserAgent().IndexOf
                    ("iPhone", StringComparison.OrdinalIgnoreCase) >= 0)
            });

Is there a similar feature in Web Forms?

If at all possible, I don't want to create a separate Mobile folder with a Mobile masterpage and check in the preinit event and switch over to render my mobile masterpage. It's obviously not as flexible for checking the specific type of mobile device, etc.

Was it helpful?

Solution

You can use Request.Browser.IsMobileDevice to detect a mobile device and adapt your rendering. Preferable with an uptodate mobile device list, you can use for example 51degrees.mobi for that.

Here is an extensive whitepaper to help you on your way.

Edit:

According to the whitepaper: "This is easy to do. For example, you can add a PreInit handler such as the following to a Web Form:

protected void Page_PreInit(object sender, EventArgs e)
{
    if (Request.Browser.IsMobileDevice)
        MasterPageFile = "~/Mobile.Master";
}

"

If 51degrees.mobi provides you with the exact mobile device, you can set the masterpagefile for your different devices there.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top