1

I have start and stop buttons and i use it to start and stop window service on server.
When i click on start button service starts but it take some time to start the service within that time span means to start the service. I have to disable start button on client side, same thing to disable stop button.

while button is disabled i have used below code btnStart disable but windows service not starts ...

javascript

 function btnStartClick()
 {
 $("input[ID=btnStart]").attr("disabled", "disabled");
 }

C#

protected void btnStart_Click(object sender,EventArgs e)
{
//service starst code here
}

Markup

 <asp:Button ID="btnStart" runat="server" Text="Start" OnClientClick="return btnStartClick();" OnClick="btnStart_Click" />
John Saunders
  • 160,644
  • 26
  • 247
  • 397
IMMORTAL
  • 2,707
  • 3
  • 21
  • 37
  • 2
    You are probably looking for this: http://stackoverflow.com/questions/2879175/disable-buttons-on-post-back-using-jquery-in-net-app Your problem is that your OnClick event is not going to fire for a disabled element. Hide the button instead. – MikeSmithDev Jan 11 '13 at 14:14

6 Answers6

0

why don't u use '#'.. instead of property selector.. this is much faster and efficient than the one you are using

$('#<%= btnStart.ClientID %>').attr("disabled", "disabled");
bipen
  • 36,319
  • 9
  • 49
  • 62
  • This won't work as `btnStart` is the ASP.NET id, not the client ID accessible in the DOM. `$('#<%= btnStart.ClientID %>')` would be the correct approach. – webnoob Jan 11 '13 at 14:15
  • thanks...but i was just tryin to tell OP, you can use direct selector... anywasy how about now?? i think this should work.. – bipen Jan 11 '13 at 14:17
0
$('#<%= btnStart.ClientID %>').attr("disabled", "disabled");
huMpty duMpty
  • 14,346
  • 14
  • 60
  • 99
0

If i understand you right.

You can send ajax request to asp page where you have your service start logic and disable button in this moment, after that check your ajax response if your service start you enable button, if not show message or handle it in any other way.

If you ask only how to disable button with jQuery, look humpty dumpty or bipen answer.

Ishikawa Yoshi
  • 1,779
  • 8
  • 22
  • 43
0

You have a couple of options:

$('#<%= btnStart.ClientID %>').prop("disabled", true);

Use ASP.NET to select OR:

$("input[id$=btnStart]").prop("disabled", true);

Every input with ID ending with btnStart which is sometimes useful when your control isn't in scope.

As another comment pointed out, once the button has been disabled it might not fire the codebehind onClick so in that case it would be better to hide / readonly the button instead of disabling it.

webnoob
  • 15,747
  • 13
  • 83
  • 165
0

His problem isn't that he can't disable button, it's that he wants his OnClick event to fire. His button click event is not going to fire for a disabled button.

If you are trying to prevent future clicks, you can hide the button, then disable it from the code-behind:

<script>
    function btnStartClick() {
        $("#<%= btnStart.ClientID %>").hide();
        return true;
    }
</script>

and code behind:

protected void btnStart_Click(object sender, EventArgs e)
{
     btnStart.Enabled = false;
     //service starts code here
}
MikeSmithDev
  • 15,731
  • 4
  • 58
  • 89
0

Thanks for Reply I got solution as

<asp:Button ID="btnStart" runat="server" Text="Start" OnClientClick="this.disabled = true; this.value = 'Please Wait';"
            UseSubmitBehavior="false" OnClick="btnStart_Click" />
IMMORTAL
  • 2,707
  • 3
  • 21
  • 37