Changing the Master Page via the code behind page

Discussion in 'General Computer Support' started by GusSalvador, Dec 2, 2009.

  1. GusSalvador

    GusSalvador

    Joined:
    Dec 2, 2009
    Messages:
    1
    Likes Received:
    0
    Let me start by saying I'm new to asp and any help would be greatly appreciated.

    I'm developing a mobile site for my company. Ideally I would like to detect the users browser and if its a handheld device change the the master page to a mobile friendly version. I've come up with this browser detection script and placed it in the Page_Load event of the codebehind page:

    string strUserAgent = Request.UserAgent.ToString().ToLower();
    if (strUserAgent != null)
    {
    if (Request.Browser.IsMobileDevice == true ||
    strUserAgent.Contains("iphone") ||
    strUserAgent.Contains ("blackberry") ||
    strUserAgent.Contains("mobile") ||
    strUserAgent.Contains("windows ce") ||
    strUserAgent.Contains("opera mini") ||
    strUserAgent.Contains("palm"))
    {

    Response.Redirect("DefaultMobile.aspx");

    }
    }

    Currently the script redirects to DefaultMobile.aspx....is there any way to change the master page instead?

    I tried using:

    this.MasterPageFile = "~/mobile/DefaultMobile.master";

    ...but no luck :(

    Thanks in Advance!
     
    GusSalvador, Dec 2, 2009
    #1
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.