Detecting Mobile Devices with ASP.NET

Development

I’ve no imediate use for this code, but I know wthat it will be useful in the future – especially as the number of user’s accessing websites via mobile phones and PDAs grow.

Taken from a post by truelove.

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
If Not IsPostBack Then
Dim Browser_obj As System.Web.Mobile.MobileCapabilities = CType(Request.Browser, System.Web.Mobile.MobileCapabilities)
If Browser_obj.Browser = "Pocket IE" Then
Label1.Text = "the is Pocket PC"
ElseIf Browser_obj.Browser = "IE" Then
Label1.Text = "Microsoft Internet Explorer"
ElseIf Browser_obj.Browser = "Phone.com" Then
Label1.Text = "the is Openwave"
End If
End If
End Sub

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
If Not IsPostBack Then
Dim browser As System.Web.Mobile.MobileCapabilities = CType(Request.Browser, System.Web.Mobile.MobileCapabilities)
If browser.ScreenCharactersWidth < 20 Then Label1.Text = "short text message" Else Label1.Text = "long text message" End If End If End Sub

Intellisense within SubSonic

Development

I struggled for a while this morning while trying to add SubSonic to a new web project – I was trying to fathom why, when I had followed all of my notes, the intellisence for the build provider was not displaying. In the end, the issue was solved with the help of this post.

Addendum:

Accessing the Html Header in ASP.NET 2.0

Development

Posting this for future reference:

Dim header As Web.UI.HtmlControls.HtmlHead
header = TryCast(Me.Page.Header, Web.UI.HtmlControls.HtmlHead)
If (header IsNot Nothing) Then
Dim link As New HtmlLink
link.Attributes.Add("type", "text/css")
link.Attributes.Add("rel", "stylesheet")
link.Attributes.Add("media", "screen")
link.Attributes.Add("href", "~/style.css")
header.Controls.Add(link)
End If