Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > General Computer Discussion > General Computer Support > Changing the Master Page via the code behind page

Reply
Thread Tools

Changing the Master Page via the code behind page

 
 
GusSalvador GusSalvador is offline
Junior Member
Join Date: Dec 2009
Posts: 1
 
      12-02-2009
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!
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Setting the value of a Master page's control's property using a property of the Master page Nathan Sokalski ASP .Net 25 03-04-2010 03:42 AM
Can a master page be built from another master page Zeba ASP .Net 1 02-22-2007 10:55 AM
Non-code behind to code behind John ASP .Net 2 02-19-2007 07:08 PM
seeking servlet "Master" keep getting "Master/servlet/Master" not found. Tomcat 5.0.25 Doug McCann Java 1 08-05-2004 09:16 PM
Re: Code Behind vs. no code behind: error Ben Miller [msft] ASP .Net 1 06-28-2003 01:46 AM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57