问题
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?
回答1:
<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
回答2:
<script type="text/javascript">
var DisableButton = function () {
document.getElementById("<%=LoginButton.ClientID %>").disabled = true;
};
var EnableButton = function () {
document.getElementById("<%=LoginButton.ClientID %>").disabled = false; };
</script>
回答3:
If you want to point <asp:Button ID="LoginButton
that ID, I think
document.getElementById("<%=LoginUser.ClientID %>").disabled = true;
来源:https://stackoverflow.com/questions/30069313/disable-button-using-javascript-function-in-asp-net