1 2 3 4 Previous Next 

Rendering problems with IE8


Microsoft released IE8 during Mix 2009.  Microsoft spent a lot of time making IE8 comply with the browser standards.  When you upgrade your browser to IE8 if you find the web site does not render right.  Do not worry there is a simple fix for this. 

 

There is a tag you can place in the Head section of your webpage which will force IE8 into IE7 compatibility mode.

 

<html>
<head>
  <!-- Mimic Internet Explorer 7 -->
  <meta http-equiv="X-UA-Compatible" content="IE=EmulateIE7" />
  <title>My Web Page</title>
</head>

 

 


For more info on IE8 compatibility read this article

http://msdn.microsoft.com/en-us/library/cc288325(VS.85).aspx

 

Hope this helps




Asp.Net Routing


 

New to the .Net Framework 3.5 SP 1 is the System.Web.Routing namespace.  The classes in the routing namespace allow you to use urls that do not map to a web page.

 

 

For this example I created a new web application.  To start off with lets add a reference to the system.web.routing and system.web.abstractions.  Open up the web.config file and lets add the UrlRoutingModule to the httpmodules section

 

        <httpModules>
            <add name="ScriptModule" type="System.Web.Handlers.ScriptModule, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
      <add name="UrlRoutingModule" type="System.Web.Routing.UrlRoutingModule, System.Web.Routing, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
    </httpModules>

 

Next we need to add a WebFormRouteHandler class which will be our route handler.

 

Imports System.Web.Routing
Imports System.Web.Compilation

Public Class WebFormRouteHandler
    Implements IRouteHandler

    Private _Path As String
    Public Property Path() As String
        Get
            Return _Path
        End Get
        Set(ByVal value As String)
            _Path = value
        End Set
    End Property

    Public Sub New(ByVal p As String)
        Path = p
    End Sub

    Public Function GetHttpHandler(ByVal requestContext As System.Web.Routing.RequestContext) As System.Web.IHttpHandler Implements System.Web.Routing.IRouteHandler.GetHttpHandler
        For Each value In requestContext.RouteData.Values
            requestContext.HttpContext.Items(value.Key) = value.Value
        Next
        If Not String.IsNullOrEmpty(Path) Then
            Return TryCast(BuildManager.CreateInstanceFromVirtualPath(Path, GetType(Page)), IHttpHandler)
        Else
            Return Nothing
        End If

    End Function
End Class

 

Finally we have to add global.asax so we can start the routing when the web site starts up

 

 

Imports System.Web.SessionState
Imports System.Web.Routing

Public Class Global_asax
    Inherits System.Web.HttpApplication

    Sub Application_Start(ByVal sender As Object, ByVal e As EventArgs)
        ' Fires when the application is started.
        Dim userHandler As New WebFormRouteHandler("~/user.aspx")
        With RouteTable.Routes

            ' pattern of the url to match
            .Add(New Route("user/{user}", userHandler))
        End With
    End Sub

    Sub Session_Start(ByVal sender As Object, ByVal e As EventArgs)
        ' Fires when the session is started
    End Sub

    Sub Application_BeginRequest(ByVal sender As Object, ByVal e As EventArgs)
        ' Fires at the beginning of each request
    End Sub

    Sub Application_AuthenticateRequest(ByVal sender As Object, ByVal e As EventArgs)
        ' Fires upon attempting to authenticate the use
    End Sub

    Sub Application_Error(ByVal sender As Object, ByVal e As EventArgs)
        ' Fires when an error occurs
    End Sub

    Sub Session_End(ByVal sender As Object, ByVal e As EventArgs)
        ' Fires when the session ends
    End Sub

    Sub Application_End(ByVal sender As Object, ByVal e As EventArgs)
        ' Fires when the application ends
    End Sub

End Class

 

Finally we need 2 web pages

 

Default.aspx

 

<%@ Page Language="vb" AutoEventWireup="false" CodeBehind="Default.aspx.vb" Inherits="RoutingTest._Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
    <h1>ASP.NET System.Web.Routing with WebForms sample</h1>
    <div><a href="user/ken">User test</a></div>
    </div>
    </form>
</body>
</html>

 

user.aspx

<%@ Page Language="vb" AutoEventWireup="false" CodeBehind="User.aspx.vb" Inherits="RoutingTest.User" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
            <h1>
            Users</h1>
        <div>
            User:
            <%=Context.Items("user")%></div>
        <hr />
        <div>
            Change the user in the URL.</div>
        <div>
            The WebFormRouteHandler adds the matched values to the HTTPContext.Items collection
            (exists for lifetime of request only).</div>
    </div>
    </form>
</body>
</html>

 

Hope this helps




AspNet: Open a default mailclient using code behind


A button, has to be draged on a webform, and this code has than to be pasted in a webform code behind
Public Class WebForm1
    Inherits System.Web.UI.Page
    Protected Sub Page_Load(sender As Object, e As System.EventArgsHandles Me.Load
        If Not IsPostBack Then
            Me.Button1.Text = "Send Mail"
            Me.Button1.Attributes("onClick") = "window.location = 'mailto:somebody@VB-Tips.com?subject=VBTips demo&body=I hope this helps?';"
        End If
    End Sub
End Class
>



AspNet: Astro Boys Live clock in VB.Net


Astro Boy has made a live clock in JavaScript. Here is showed how this can be used in code behind from ASPNET. For this sample is only needed a long label on a webpage and than run Private Sub Page_Load(ByVal sender As Object, ByVal e _
   As System.EventArgs) Handles MyBase.Load
   Dim str As String = "<script language=javascript >" & _
   "src='http://www.zip.com.au/~astroboy/liveclock/liveclock.js '>" & _
   "show_clock()</ script>"
   Page.RegisterClientScriptBlock("LiveClock", str)
   Label1.Text = _
   "<script language='javascript'>new LiveClock(); </ script>"
End Sub

'To use it this way is of course not fair, I here it is done to make
'the sample easy to show.
'It is nicer to download the script from Astro Boys website and
'than put it in your own project (IIS file)
'While Astro boy gives as well samples
'how to use it to let it look nicer if you use the link bellow

'http://www.zipworld.com.au/~astroboy/liveclock/



AspNet: Server Side Clock (showing the use of timer and graphics)


This clock tip is mainly meant to show:
 How to make an image from scratch;
 How to use a client side timer;
 How to use an extra page to show an image.

 

'''Form 1 Needs an imagebox on the page
Private Sub Page_Load(ByVal sender As System.Object, _
     ByVal e As System.EventArgs) Handles MyBase.Load
        Image1.Height = New Unit(32)
        Image1.Width = New Unit(200)
        Image1.Visible = True
'Beneath is the Timer
        Dim scriptString As String = "<script language=JavaScript>" & _
        "setclock(); function setclock(){document.images.Image1.src = " & _
        "'http://localhost/WebClock/WebForm2.aspx';setTimeout('setclock()',1000)}</script>"
        Page.RegisterStartupScript("setclock", scriptString)
End Sub

'''Form2 needs only an empty page
   Private Sub Page_Load(ByVal sender As System.Object, _
   ByVal e As System.EventArgs) Handles MyBase.Load
        Response.Cache.SetExpires(DateTime.Now.AddTicks(500))
        Dim myForeBrush As Brush = Brushes.Black
        Dim myFont As New Font("Times New Roman", 8, FontStyle.Regular)
        Dim textHeight As Single
        Dim bm As New Bitmap(120, 20)
        Dim g As Graphics = Graphics.FromImage(bm)
        g.Clear(Color.White)
        Dim textSize As SizeF = g.MeasureString(now.tostring, myFont)
        g.DrawString(Now.ToString, myFont, myForeBrush, _
            New RectangleF(0, 0, 120, 20))
        Dim ms As New IO.MemoryStream
        Dim arrImage() As Byte
        bm.Save(ms, Imaging.ImageFormat.Bmp)
        arrImage = ms.GetBuffer
        Response.BinaryWrite(arrImage)
        g.dispose
End Sub



1 2 3 4 Previous Next