Using One or Separate Sites for Mobile and Desktop Development

Using One or Separate Sites for Mobile and Desktop Development.
I've been spending time looking at the ongoing battles between developers over one of the fundamental headaches of web design, should you build separate sites for mobile devices and desktop computers. Some of the changes that Google have introduced like syncing your bookmarks for the IPhone and Chrome are really useful, this has led me to the single site conclusion, but a lot the code below could be used to redirect to a seperate site.
The site should be easy enough to use on either, while you can turn some things on or off with some simple detection.
There is also a cookie stored on the users device that remembers the last option selected.
This is what the detection does on this site. It is a simple dropdown with three options; Desktop, Apple and Mobile. There is also a dual menu system, which offers a simplified breadcrumb for the user as well.

HTML

<asp:DropDownList ID="SelDevice" runat="server" ClientIDMode="Static" Width="100px" AutoPostBack="True">
    <asp:ListItem>Desktop</asp:ListItem>
    <asp:ListItem>Apple</asp:ListItem>
    <asp:ListItem>Mobile</asp:ListItem>
</asp:DropDownList>
<div id="SubMenu">
    <div id="Current" runat="server" clientidmode="Static"></div>
    <div id="SubMenuList" runat="server" clientidmode="Static"></div>
</div>
Now this code is used in the Page Load event, setting the linked style sheet before rendering on the page. You could also for instance change the visibility of certain items within the If statement.

VB

Protected Sub Page_Load(ByVal sender As ObjectByVal e As System.EventArgsHandles Me.Load
    If Session("View"Is Nothing Then
        If Request.Cookies("ViewType"Is Nothing Then
            If Request.Browser.IsMobileDevice = True Then
                Dim ua As String = Request.UserAgent.ToString().ToLower()
                If ua.Contains("iphone"Or ua.Contains("ipad"Or ua.Contains("ipod"Then
                    Session("View") = "Apple"
                Else
                    Session("View") = "Mobile"
                End If
            Else
                Session("View") = "Desktop"
            End If
        Else
            Session("View") = Request.Cookies("ViewType").Value.ToString
        End If
    End If
    SelDevice.SelectedValue = Session("View").ToString
    If Session("View").ToString = "Apple" Then
        cssLink.Href = "/gsclaytonmob.css"
    ElseIf Session("View").ToString = "Mobile" Then
        cssLink.Href = "/gsclaytonmobold.css"
    Else
        cssLink.Href = "/gsclayton2.css"
    End If
    GetMenus()
End Sub
In the code above you would replace the setting of CSS with a redirect.
We will need some code to recognise that the user has changed their view type. We will also stored a cookie here to remember the value next time they access the site.

VB

Protected Sub SelDevice_SelectedIndexChanged(sender As Object, e As EventArgsHandles SelDevice.SelectedIndexChanged
    Session("View") = SelDevice.SelectedValue
    Response.Cookies("ViewType").Value = Session("View")
    Response.Cookies("ViewType").Expires = DateTime.Now.AddDays(1000)
    If Session("View").ToString = "Apple" Then
        cssLink.Href = "/gsclaytonmob.css"
    ElseIf Session("View").ToString = "Mobile" Then
        cssLink.Href = "/gsclaytonmobold.css"
    Else
        cssLink.Href = "/gsclayton2.css"
    End If
    GetMenus()
End Sub
Once the menu type has been set we can also populate the menu manually in code behind, adding the references dependant on the menu provided.

VB

Protected Sub GetMenus()
    Dim m As String = Page.RouteData.Values("PageMenu")
    Select Case m
        Case "Home"
            'HomeSubMenu.Attributes.CssStyletyle = "Active"
            Current.InnerHtml = "Home"
            Dim a As New HyperLink
            a.NavigateUrl = "Home/"
            a.Text = "Home"
            SubMenuList.Controls.Add(a)
            Dim b As New HyperLink
            b.NavigateUrl = "About/"
            b.Text = "About"
            SubMenuList.Controls.Add(b)
            Dim c As New HyperLink
            c.NavigateUrl = "Login/"
            c.Text = "Login"
            SubMenuList.Controls.Add(c)
    End Select
End Sub
You can then style each of the Menus differently in your CSS, for example each of the links in my Sub Menu area are styled differently. The first one is for mobile (full width), and the second for desktop.

CSS

#SubMenu a
{
color#332700;
floatleft;
width100%;
displayblock;
text-decorationnone;
padding5px 0px 5px 0px;
font-sizelarge;
border-bottom1px solid Grey;
}
#SubMenu a
{
color#45144D;
padding-left8px;
floatright;
text-decorationnone;
}
Let me know your opinions?
Ousia Logo