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
    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. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Corbin O'Reilly
    Replies:
    2
    Views:
    3,172
    Corbin O'Reilly
    May 26, 2004
  2. AM
    Replies:
    1
    Views:
    369
    Walter Roberson
    Mar 7, 2005
  3. =?Utf-8?B?UmVjb24=?=

    Anyway to manually set a never-changing master browser?

    =?Utf-8?B?UmVjb24=?=, Jan 20, 2006, in forum: Wireless Networking
    Replies:
    2
    Views:
    11,723
    =?Utf-8?B?UmVjb24=?=
    Jan 20, 2006
  4. jaanazam
    Replies:
    2
    Views:
    8,215
    ziyad6
    Aug 28, 2008
  5. shah_satish2002

    VHDL code for SPI Master

    shah_satish2002, Jul 10, 2007, in forum: Hardware
    Replies:
    2
    Views:
    2,622
    vlsi.engg27
    Jul 22, 2007
Loading...

Share This Page