2

I have code that looks like this:

Protected Sub unearned_ServerClick(ByVal sender As Object, ByVal e As System.EventArgs) Handles unearned_run.ServerClick
    Dim DataOut As String "a,b,c"
    unearned_span.InnerHtml = unearned_policytype.Value
    Response.Clear()
    Response.AddHeader("Content-Disposition", "attachment; filename=Unearned.csv")
    Response.ContentType = "application/octet-stream"

    Response.AddHeader("Content-Length", DataOut.Length())
    Response.Write(DataOut)
End Sub

and the html:

<form id="form1" runat="server">
    <div id="unearnedreport" style="display:none">
        <input id="unearned_run" type="button" runat="server" value="Run Report" />
        <span id="unearned_span" runat="server"></span>
     </div>
</form>

The problem I am trying to solve is that when the report runs I do not get a busy pointer. However, I do get a busy pointer if hover my pointer in the very bottom of the browser window; specifically in the area that has the menu to choose magnification.

Note: I am not a Windows programmer so if you could give answer without a lot of assumptions about what I know about .NET I would appreciate it.

GSerg
  • 76,472
  • 17
  • 159
  • 346
Be Kind To New Users
  • 9,672
  • 13
  • 78
  • 125
  • Possible duplicate of [Changing the cursor in asp.net](http://stackoverflow.com/q/2821309/11683) – GSerg Apr 17 '17 at 20:58
  • Changing the cursor on the `unearned` click is easy. The trick is getting it back to normal. Since you are sending a CSV file to the client and not a html page, the cursor will continue to be the `busy` one indefinitely. A possible trick would be to change it back after x seconds, but if the download takes longer there is no way to check and postpone the change. – VDWWD Apr 19 '17 at 18:38

3 Answers3

3

You mention you are not a "windows programmer" but if this was windows and not web the answer would have been easy. In windows you would place a line of code

Cursor.Current = Cursors.WaitCursor; //event handler start

Cursor.Current = Cursors.Default; //event handler end

In an asp.net webforms environment however you have to realize that the click event on the browser causes the page to post back to the server and then your code runs on the server and then html is being generated on the server and only when your Response.Write(DataOut) is finished will this page on the server be given back the client browser to render it. So you need to run something in the actual client browser (only javascript can work client side) to show a visual cue and this cue will continue showing until the server finishes and your response page starts showing in the browser. Look at C# Webforms show Loading indicator during code execution If you find the linked example useful, please give bounty to that user(Dennis R).

Community
  • 1
  • 1
HPWP7
  • 96
  • 6
  • Although this got the bounty by default I could not get it to work. I think it is because this is focused on waiting for a page to load and I am waiting for a file to download. I am not smart enough to adapt it. I have not given up. – Be Kind To New Users May 12 '17 at 22:31
1

We can achieve this by using the BlockUI a Jquery Plugin that can be integrated into the asp.net Webforms , you can use this for not only to this in every application it can be used to wait the user till the action is completed .

Here is how you integrate to your application :

  1. Add the Jquery and Block UI script tag to the page

  2. Add UiBlock class to your unearned button

  3. Add the following script

       $('.UiBlock').click(function () {
            $('.blockMe').block({
    
                css: {
                    border: 'none',                          
                    backgroundColor: '#fff',
                    '-webkit-border-radius': '10px',
                    '-moz-border-radius': '10px',
                    opacity: .8,
                    color: '#000'
                }
            });
        });
    

On your every click event before calling the server code this will be called and it will be closed after getting the data.

We implemented it and works for your need as well .

Krsna Kishore
  • 8,233
  • 4
  • 32
  • 48
  • I tried this but it does not work. What is a technique I can use to debug if it is running? I added an alert() as the first line in the function and it did NOT trigger. – Be Kind To New Users May 12 '17 at 22:38
  • This is what my button looks like when I view it in the DOM Explorer: `` – Be Kind To New Users May 12 '17 at 23:03
  • @MichaelPotter you came after a long time i guess :) , one way to debug is write `debugger` in your JS code and can see the breakpoint hitting from the Console. it should work we been implementing in our projects , if need my support ping me to chat will drive you through. – Krsna Kishore May 13 '17 at 04:20
0

you need a reference to the .net's javascript async library, as well as additional code like update-panels to have .net do this for you , if indeed you want to leave it to all the javascript this produces to do it for you.

you will also need to put any code you want processed in an update panel.

this should help you get started:

https://msdn.microsoft.com/en-us/library/bb386573.aspx

once you get a handle of this, and want a mousepointer to change, and not say show "loading image gif", you can do that as well, with a bit more code.

O. Gungor
  • 758
  • 5
  • 8