How do I change the cursor to a Wait cursor in ASP.NET?

Often when a user clicks something on your ASP.NET web page the server side code goes off and executes a long running process. In a Winforms application you could change the cursor to a wait or hourglass cursor to inform the user that the application is busy.

With ASP.NET pages this is a bit more of a problem to do. You need to employ a little JavaScript.

Add this JavaScript between the <HEAD> tags on your ASP.NET web page:

   function setHourglass()
  { = 'wait';

Now you have to tell the web form to run the JavaScript funciton when a post back happens.

Add this to your <BODY> tag:

   <body onbeforeunload="setHourglass();" onunload="setHourglass();">

The onbeforeunload and onunload events in Internet Explorer fire prior to the page unloading during the start of the post back operation. The cursor will change to an hourglass then when the page gets posted back and re-renders, the cursor is set back to the default.

Or, you can add the following line to the FORM tag instead.

   <form runat="server" onsubmit="return setHourglass();">

About TheScarms
About TheScarms

Sample code
version info

If you use this code, please mention ""

Email this page

© Copyright 2024 TheScarms
Goto top of page