1

I have an asp.net web application that when you click a button it excecutes all my stuff but it is slow it takes 10 to 15 seconds to work and i dont want users to spam click the button while the site is busy. So my plan was to disable the button and have the label below it become buesy and say "Running" and after it was done the button would reactivate and the label would say "Done" but this dident work as planned here is my code for the button listener.

 protected void SubmitButton_Click(object sender, EventArgs e)
    {
        SubmitButton.Enabled = false;
        RunStatus.Text = "Running";
        RunStatus.Visible = true;
        ErrorField.Visible = false;

//i deleted all my code that actually does the stuff that takes time from here

        RunStatus.Text = "Done";
        SubmitButton.Enabled = true;
    }

the problem is that all the visual stuff happens after the method is run so while it is running nothing changed but after it has the text feild show done. I would also be happy to have a busy cursor but that is of secondary importance.

FLG
  • 163
  • 2
  • 10
  • use jQuery that show a loading circle like any other Web Applications. That will save you a lot of works.. – neimad Jul 30 '12 at 15:20

2 Answers2

2

Wrap your button in an UpdatePanel and use the UpdateProgress control to show the client that an AJAX call is taking place. See this tutorial for more information.

Mihai
  • 2,835
  • 2
  • 28
  • 36
0

I'm really sorry but you have a fundamental gap in your knowledge about the ASP.NET page lifecycle. It's really very different from Windows Forms - which is what the kind of code you've posted would be applicable to.

I respectfully suggest you grab a decent book on ASP.NET and try to build up a basic understanding about ASP.NET's abstraction over HTTP/HTML.

tomfanning
  • 9,552
  • 4
  • 50
  • 78
  • 1
    I am aware that my ASP.NET skills are severly lacking beacuse i am just starting to use it, but the code i have shown here is from my sap.net web appilcation and it works that listener is called when i click that button. I have created a website with it. No its not a fancy mvc application but it works and from my web site i run my c# code and my program runs.So with all due respect no this is not code for a Windows Forms Application. – FLG Jul 30 '12 at 15:51
  • 1
    Hmmm, let me try again. The reason your code doesn't work as expected is because in ASP.NET, the server won't start sending rendered page output back to the client until after your `SubmitButton_Click` method completes. Until the framework starts sending markup back to the client, the rendered page exists only as an abstract concept on the server - so when you set `RunStatus.Text = "Running";` then `RunStatus.Text = "Done";`, the first statement does literally nothing. It's this fundamental difference I'm respectfully referring you to. Good luck! – tomfanning Aug 02 '12 at 22:23