I am checking if user exists in database if exists I am showing message as "existed user" and then I need to disable the signup button if not I need to enable it.
I am unable to enable and disable the sign Up button.
Can anyone help me in this issue?
Here is my code:
 <script type="text/javascript">
     $(function () {
         $("#<% =btnavailable.ClientID %>").click(function () {
             if ($("#<% =txtUserName.ClientID %>").val() == "") {
                 $("#<% =txtUserName.ClientID %>").removeClass().addClass('notavailablecss').text('Required field cannot be blank').fadeIn("slow");
             } else {
                 $("#<% =txtUserName.ClientID %>").removeClass().addClass('messagebox').text('Checking...').fadeIn("slow");
                 $.post("LoginHandler.ashx", { uname: $("#<% =txtUserName.ClientID %>").val() }, function (result) {
                     if (result == "1") {
                         $("#<% =txtUserName.ClientID %>").addClass('notavailablecss').fadeTo(900, 1);
                       document.getElementById(#<% =btnSignUp.ClientID %>').enabled = false;
                     }
                     else if (result == "0") {
                         $("#<% =txtUserName.ClientID %>").addClass('availablecss').fadeTo(900, 1);
                        document.getElementById('#<% =btnSignUp.ClientID %>').enabled = true;
                     }
                     else {
                         $("#<% =txtUserName.ClientID %>").addClass('notavailablecss').fadeTo(900, 1);
                     }
                 });
             }
         });
         $("#<% =btnavailable.ClientID %>").ajaxError(function (event, request, settings, error) {
             alert("Error requesting page " + settings.url + " Error:" + error);
         });
     });
</script>
                To disable a button using only JavaScript you need to set its disabled property to false . For example: element. disabled = true . And to enable a button we would do the opposite by setting the disabled JavaScript property to false .
To make the disabled button, we will use the Pure CSS class “pure-button-disabled” with the class “pure-button”. We can also create a disabled button using disabled attribute.
Try this...
document.getElementById('<%= button.ClientID %>').disabled = true;
OR
document.getElementById('<%= button.ClientID %>').disabled = false;
                        JavaScript:
 function Enable() {
      $("#btnSave").attr('disabled', false);                
    }
 function Disable() {
       $("#btnSave").attr('disabled', true);
    }  
ASPX Page:
 <asp:Button runat="server" ID="btnSave" Text="Save" UseSubmitBehavior="false" OnClientClick="if(Page_ClientValidate('Validation')){javascript:Disable();}" ValidationGroup="Validation"/>
Code Behind:
ScriptManager.RegisterStartupScript(Me, Me.GetType(), "Disable", "javascript:Disable();", True)
                        If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With