locked
event to disable button very first time RRS feed

  • Question

  • User279786496 posted

    <td style="vertical-align: top;">

    <input type="button" id="btn1" onclick="Hide()" value="Do" /></td>

    I want to disable the button 'Do', I tired with enabled  = true but its not working.

    Thursday, August 3, 2017 1:01 PM

All replies

  • User2103319870 posted

    I tired with enabled  = true but its not working.

    You can use the disabled property to disabled a button

    <input type="button" id="btn1" onclick="Hide()" value="Do"  disabled/>
    Thursday, August 3, 2017 1:14 PM
  • User279786496 posted

    it got disabled now, but it has to be enabled when I select any one of the data in drop down list

    I have written the code in the javascript is this the correct one?

     <td style="vertical-align: top;">

    <input type="button" id="btnN" onclick="TestHide()" value="Do" disabled/></td>

     In the same aspx file I have created the var called btNclientID

    <script type="text/javascript">

    var _btnNClientID = "<%= btnN.ClientID %>";

    Written a function  in the javascript

    function

    EnableOrDisableDoButton() {

       var btnN = $find(_btnNClientID);

        btnN.set_enabled(GetSelectedIdsCount() > 0);

    }

    Thursday, August 3, 2017 1:28 PM
  • User2103319870 posted

    btnN.set_enabled(GetSelectedIdsCount() > 0);

    }

    From your other posts on forum, I am guessing you are using Telerik Controls. In your JavaScript function you are using set_enabled function which is a telerik control function. However you are using a html button. Hence you code wont work.

    Try using below code

     function EnableOrDisableDoButton() {
                    var btnN = $find(_btnNClientID);
    
                    if (GetSelectedIdsCount() > 0) {
                        //Enable the buttom
                        btnN.prop('disabled', false);
                    }
                }

    Thursday, August 3, 2017 2:50 PM
  • User279786496 posted

    It throw error

    The value of property If is undefined or null , not a function object.

    Thursday, August 3, 2017 6:45 PM
  • User347430248 posted

    Hi BerrySmith,

    you can also try to refer example below.

    <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="WebApplication74.WebForm1" %>
    
    <!DOCTYPE html>
    
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
        <title></title>
        <script type="text/javascript">
            function btnvisible()
            {
               
                document.getElementById("btn_click").disabled = false;
            }
        </script>
    </head>
    <body>
        <form id="form1" runat="server">
        <div>
        
            <asp:DropDownList ID="DropDownList1" runat="server" onclick="btnvisible()" Height="16px" Width="158px">
                <asp:ListItem>One</asp:ListItem>
                <asp:ListItem>Two</asp:ListItem>
                <asp:ListItem>Three</asp:ListItem>
                <asp:ListItem></asp:ListItem>
            </asp:DropDownList>
        <br/>
            
            <button type="button" id="btn_click" onclick="Hide()" value="Do" disabled>Click Me!</button> 
        </div>
        </form>
    </body>
    </html>
    

    Output:

    Regards

    Deepak

    Friday, August 4, 2017 1:59 AM