ASP.NET - Code Samples - Display Animated Gif during postback in IE

ASP.NET Keep an animated gif from freezing after triggering a postback.

Synopsis:

When a postback is triggered by an event such as a button click and the client is using Microsoft Internet Explorer (IE 6), animated gifs will freeze, i.e. their animation stops. The only solution I could find was to set a timeout to refresh the image src property of an image a few milliseconds after the form is submitted.
If you're looking for some animated wait icons, a small collection is located at www.sanbaldo.com.
You can easily modify any you may like at this online animated gif editor, which is great for doing things like shifting the color of a gif from red to blue or green: http://www.gifworks.com.

The Code:

For this example to work you will need:
-an 'images' directory containing an image named "busy.gif"
-an image control named: image1 with it's source set to "images/busy.gif"
-a server side button named: button1

Aspx File - Add this script inside the head tags
    <script language="javascript">
	function UpdateImg(ctrl,imgsrc) {
		var img = document.getElementById(ctrl);
		img.src = imgsrc;
	}
    </script>

Code Behind
    Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        
        Button1.Attributes.Add("onclick", "setTimeout(""UpdateImg('image1','images/busy.gif');"",50);")
       
    End Sub

About this page: