简体   繁体   中英

disable button using javascript function in asp.net

i am having a problem trying to disable a button, here is my javascript function:

<script type="text/javascript">
     var DisableButton = function () {
        document.getElementById("<%= LoginButton.ClientID %>").disabled = true;
    };
    var EnableButton = function () {
        document.getElementById("<%= LoginButton.ClientID %>").disabled = false;         };
   </script> 

and this is where the button is located

<asp:Login ID="LoginUser" runat="server" EnableViewState="false" RenderOuterTable="false">
    <LayoutTemplate>

        <%-- some elements here: text boxes, etc --%>

        <div>
            <p class="submitButton">
                <asp:Button ID="LoginButton" runat="server" CommandName="Login" Text="Log In"
                ValidationGroup="LoginUserValidationGroup"/>
            </p>
        </div>
    </LayoutTemplate>
</asp:Login>

it worked in the other pages.. but here, i get this error

Description: 
An error occurred during the compilation of a resource required to service this request.
Please review the following specific error details and modify your source code appropriately. 

Compiler Error Message:
CS1061: 'System.Web.UI.WebControls.Login' does not contain a definition 
for 'LoginButton' and no extension method 'LoginButton' accepting a first argument of type
'System.Web.UI.WebControls.Login' could be found (are you missing a using directive or an assembly reference?)


Source Error:
document.getElementById("<%= LoginButton.ClientID %>").disabled = true;

additionally, i am calling these functions from google recaptcha events:

<div id="asd" class="g-recaptcha" data-callback="EnableButton" data-expired-callback="DisableButton" data-sitekey="site_key">

What am i doing wrong here? Did i miss something?

<script type="text/javascript">
    function DisableButtons()
    {
    document.getElementById ("<%=Button2.ClientID %>").disabled = true;
    document.getElementById ("<%=Button3.ClientID %>").disabled = true;
    return true ;
    }
    </script>
    <asp:Button ID="Button1" runat="server" Text="Button" OnClientClick="return DisableButtons()" />
    <asp:Button ID="Button2" runat="server" Text="Button" />
    <asp:Button ID="Button3" runat="server" Text="Button" />

And more information use Instantly disable Button on click

Disabling Buttons within C# method

<script type="text/javascript">
         var DisableButton = function () {
            document.getElementById("<%=LoginButton.ClientID %>").disabled = true;
        };
        var EnableButton = function () {
            document.getElementById("<%=LoginButton.ClientID %>").disabled = false;         };
 </script> 

如果您想指向<asp:Button ID="LoginButton那个ID,我认为

document.getElementById("<%=LoginUser.ClientID %>").disabled = true;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM