Waiting image between page loads, with master templates

TheWizardofInt

Junior Contributor
Joined
Dec 31, 1969
Messages
333
Location
Orlando, FL
This was one of those things that was too easy to get, so I thought I would post it here and save the next person some grief

In your master template, put this in your code behind:

Code:
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        If Not Page.IsPostBack Then
'create an image here - this can be any img that already exists on the site
            Response.Write("<img id='img1' src ='images/red-x.gif' Style='left: 500px; position: absolute; top: 200px' />")
            Response.Write("<script language=javascript>;")
            Response.Write("var dots = 0;")
            Response.Write("var dotmax = 10;")
            Response.Write("function ShowWait(){")
            Response.Write("}")
            Response.Write("function StartShowWait(){")
            Response.Write("var output;")
            Response.Write("output=document.getElementById('img1');")
            Response.Write("output.style.visibility='visible';")
            Response.Write("window.setInterval('ShowWait()',1000);")
            Response.Write("}")
            Response.Write("function HideWait(){")
            Response.Write("var output;")
            Response.Write("output=document.getElementById('img1');")
            Response.Write("output.style.visibility = 'hidden';")
            Response.Write("window.clearInterval();")
            Response.Write("}")
            Response.Write("StartShowWait();</script>")
            Response.Flush()
            Thread.Sleep(10000)
        End If
    End Sub

At the top of the page, add 'Imports System.Threading to accomodate the Thread.Sleep

Now, on the HTML source for the Master Template page, go to the Body line and add

Code:
onload="HideWait();

Don't forget the semicolon or it won't work

Now this image pops up as pages load and, when the page is DONE loading, it executes the Javascript 'HideWait' function and kills the image. You don't have to do anything to any of the other pages
 
Back
Top