Jquery Code: $('[...">

JQuery Asp.net Button Disabled

html code:

<asp:Button runat="server" ID="btnTest" Text="Test" OnClick="btnTest_Click" /> 

Jquery Code:

 $('[id$=btnTest]').click(function(){ $('[id$=btnTest]').attr('disabled', 'true'); }); 

CodeBehind:

 protected void btnTest_Click(object sender, EventArgs e) { //here not come. } 

Code For btnTest event not working?

+6
javascript jquery
source share
6 answers

I think that turning on the button in the click event handler prevents the postback. Try disabling the code after a while:

 $('[id$=btnTest]').click(function(){ var button = this; setTimeout(function() { $(button).attr('disabled', 'disabled'); }, 100); }); 
+8
source share

Try using the jQuery class selector:

  • Add CssClass="MyButton" to your ASP.NET button;
  • Use this selector in jQuery
  • Set disabled="disabled" attribute when clicked

JQuery

 $('button.MyButton').click(function(){ $(this).attr('disabled', 'disabled'); }); 
+1
source share

The code example uses ends with a selector. There is no error in the selector. you just need to change code like this

 $('[id$=btnTest]').click(function () { $('[id$=btnTest]').attr('disabled', true); }); 

I tested this and it works great without any problems.

+1
source share

You just did not need to do the following:

 btnTest.Enabled = False; 

in the code file? This will result in a return message, but it should work.

0
source share

I can solve your problems: $(".classButton").prop('disabled','disabled'); and remove disabled: $(".classButton").prop('disabled', ''); $(".classButton").prop('disabled','disabled'); and remove disabled: $(".classButton").prop('disabled', '');

0
source share

This will not work because the generated HTML identifier is different from the ASP.NET identifier.

Thus, btnTest will be displayed as a different identifier.

A quick dirty way is to start the page, look at the HTML source code and find the identifier of the generated button and pass it as a compression in the jQuery function.

The best way is to create a jQuery function through code:

 Literal1.Text = "$('[id$=" + btnTest.ClientId + "]').click(function( {$(this).attr('disabled', 'disabled');});"; 

Edit : Also, I could not help but understand that your OnClick attribute should point to btnTest_Click , not btn_Click

-2
source share

All Articles