Changing the cursor in ASP.NET while loading doesn't work without a JS alert

Bob Avallone picture Bob Avallone · May 12, 2010 · Viewed 19.8k times · Source

I want to change the cursor to an hourglass in my asp.net application to let my users know that the process is running. I searched for an answer and was advised to use JavaScript as follows:

  1. Add this JavaScript:

    function hourglass() {
        document.body.style.cursor = "wait";
    }
    
  2. then in my code in the page load event:

    btnImport.Attributes.Add("onclick", "javascript: hourglass();");
    

Where btnImport is the button they click on.

However this does not work. If I add an alert to the hourglass function. it does work. Is there some way to get this to work without the alert?

Answer

azamsharp picture azamsharp · May 12, 2010

How about this:

btnImport.Attributes.Add("onclick", "hourglass();");