VS.NET - ASP.NET - Wait Screen Control

ASP.NET- Wait Screen Control - Converted to vb.net

Synopsis:

A few weeks ago I came across a link to this article at lennybacon.com which was linked off of the official asp.net page. This WaitScreen Control code was something that I had wanted to implement in one of my projects for a while. While Daniel Fisher's control gives a good look at how to create a custom WaitScreen asp.net control the code is written in C#. Since I wanted to try out this code, but all my work needs to be done in vb.net I had to convert it. Daniel kindly allowed me to put up my attempt at converting his code for anyone else who needs it. Some features in the conversion only work for vs 2005. I have included downloads to my code for both VS 2003 and vs 2005. Additionally I set the default namespace of the vb project rather than explicitly code the namespace. I did this because of issues I was having with the toolbox bitmap functionality, i.e, it was he only way I could ge the bitmapicon to work for the control.

Note: In the aspx file you must set the OnProcess property of control to an event such as the WaitScreen_Process as described in the article at lennybacon.com

Solution:

Download : 
VS 2003 Dll and Code
VS 2005 Dll and Code

For VS 2005: WaitScreen.vb
Imports System.ComponentModel
Imports System.Web.UI
Imports System.Drawing
Imports System.Web.UI.WebControls

'''<summary>
'''The WaitScreen control displays a grafic while a long running operation 
'''is running.
'''</summary>

<Designer("StaticDust.Web.UI.Controls.WaitScreenDesigner")> _
<ToolboxBitmap(GetType(WaitScreen), "WaitScreen.ico")> _
   Public Class WaitScreen : Inherits WebControl
    ' This field holds the URL pointing to an image
    Private m_ImageUrl As String = "images/busy.gif"

    ' these comments won't do anything for vb 2003... sorry.
    ''' <summary> Gets/sets the URL pointing to an image.</summary>
    ''' <value>A <see cref="string">string</see> containing the URL pointing 
    ''' to an image..</value>
    ''' <remarks>This property gets/sets the URL pointing to an image.
    ''' </remarks>
    <Description("Gets/sets the URL pointing to an image.")> _
    Public Property ImageUrl() As String
        Get
            Return m_ImageUrl
        End Get
        Set(ByVal Value As String)
            m_ImageUrl = Value
        End Set
    End Property


    Public Delegate Sub ProcessHandler(ByVal sender As Object, ByVal e As EventArgs)

    ' more comments vb.net 2003 can't use
    ''' <summary>
    ''' The process event.
    ''' </summary>

    Public Event Process As ProcessHandler
    ''' <summary>
    ''' Triggers the Process event.
    ''' </summary>

    Public Overridable Sub OnProcess()
        RaiseEvent Process(Me, Nothing)
    End Sub

    ''' <summary>
    ''' Triggers the Load event.
    ''' </summary>

    Protected Overrides Sub OnLoad(ByVal e As EventArgs)

        Dim nl = Environment.NewLine

        MyBase.OnLoad(e)
        Page.Response.Buffer = True
        Page.Response.Write(String.Concat( _
       "<script type=""text/javascript""> " + nl + nl + _
       "//<![CDATA[" + nl + nl + _
       "<!--" + nl + nl + " " + nl + nl + _
       "if(document.getElementById) " + nl + nl + _
       "{ // IE 5 and up, NS 6 and up" + nl + nl + _
       "    var upLevel = true;" + nl + nl + "}" + nl + nl + _
       "else if(document.layers) " + nl + nl + _
       "{ // Netscape 4" + nl + nl + _
       "    var ns4 = true;" + nl + nl + "}" + nl + nl + _
       "else if(document.all) " + nl + nl + _
       "{ // IE 4" + nl + nl + _
       "    var ie4 = true;" + nl + nl + _
       "}" + nl + nl + " " + nl + nl + _
       "function showObject(obj) " + nl + nl + _
       "{" + nl + nl + _
       "    if (ns4) " + nl + nl + _
       "    {" + nl + nl + _
       "        obj.visibility = 'show';" + nl + nl + _
       "    }" + nl + nl + _
       "    else if (ie4 || upLevel) " + nl + nl + _
       "    {" + nl + nl + _
       "        obj.style.visibility = 'visible';" + nl + nl + _
       "    }" + nl + nl + _
       "}" + nl + nl + nl + nl + _
       "function hideObject(obj) " + nl + nl + _
       "{" + nl + nl + _
       "    if (ns4) " + nl + nl + _
       "    {" + nl + nl + _
       "        obj.visibility = 'hide';" + nl + nl + _
       "    }" + nl + nl + _
       "    if (ie4 || upLevel) " + nl + nl + _
       "    {" + nl + nl + _
       "        obj.style.visibility = 'hidden';" + nl + nl + _
       "    }" + nl + nl + _
       "}" + nl + nl + _
       "// -->" + nl + nl + _
       "//]]>" + nl + nl + _
       "</script>" + nl + nl + _
       "<div id=""splashScreen""><img src=""" & _
        New Control().ResolveUrl(m_ImageUrl) & _
        """ alt=""busy"" /></div>"))


        Page.Response.Flush()
        OnProcess()
        Page.Response.Flush()

        Page.Response.Write( _
        "<script type=""text/javascript""> " + nl + nl + _
        "//<![CDATA[" + nl + nl + _
        "<!--" + nl + _
        "var splash" + nl + nl + _
        "if(upLevel) " + nl + nl + _
        "{" + nl + nl + _
        "    splash = document.getElementById('splashScreen');" + nl + nl + _
        "}" + nl + nl + _
        "else if(ns4) " + nl + nl + _
        "{" + nl + nl + _
        "    splash = document.splashScreen;" + nl + nl + _
        "}" + nl + nl + _
        "else if(ie4) " + nl + nl + _
        "{" + nl + nl + _
        "   splash = document.all.splashScreen;" + nl + nl + _
        "}" + nl + nl + _
        "hideObject(splash);" + nl + nl + _
        "// -->" + nl + nl + _
        "//]]>" + nl + nl + _
        "</script>" + nl + nl)

    End Sub 'OnLoad 

End Class
WaitScreenDesigner.vb
Imports System.Web.UI.Design

Public Class WaitScreenDesigner : Inherits ControlDesigner
    Public Overrides Function GetDesignTimeHtml() As String
        Dim imageUrl As String = DirectCast(Me.Component, WaitScreen).ImageUrl
        Dim webApp As IWebApplication = _
            DirectCast(Component.Site.GetService(GetType(IWebApplication)), IWebApplication)
        Dim item As IProjectItem = webApp.GetProjectItemFromUrl("~/" & imageUrl)
        Return String.Concat("<img src=""", item.PhysicalPath & "\""alt='Please wait...' />")
    End Function
End Class
About this page: