¿Cómo deshabilitar el botón en el evento de clic?
Frecuentes
Visto 1,957 veces
3 Respuestas
6
You just have to set it's Enabled
perfecta a false
en el lado del servidor:
button.Enabled = false;
Editar: Si button
is a link and it doesn't work in other browsers than IE, have a look at following link: http://www.aspnetajaxtutorials.com/2009/05/how-to-enable-or-disable-linkbutton-in.html
<asp:LinkButton ID="lnkTest" runat="server" CommandArgument="1" CommandName="1x"
OnClick="lnkTest_Click">Test</asp:LinkButton>
Style for enabling and Disabling is
<style>
.LnkEnabled
{
cursor: pointer;
}
.LnkDisabled
{
cursor: default;
color: Gray;
}
</style>
función javascript
<script language="javascript">
function EnableLinkButton(ID,flag)
{
document.getElementById(ID).onclick=function(){return flag;};
if(!flag)
{
document.getElementById(ID).setAttribute("disabled","disabled");
document.getElementById(ID).className="LnkDisabled";
}
else
{
document.getElementById(ID).setAttribute("disabled","");
document.getElementById(ID).className="LnkEnabled";
}
}
EnableLinkButton('<%= lnkTest.ClientID %>',false);
</script>
Edit2: If that doesn't work (haven't tested it), you could also try this:
button.Attributes.Add("onClick", "return !this.disabled;")
Respondido 28 ago 12, 13:08
0
$('#button_id').attr('disabled', 'disabled');
Respondido 28 ago 12, 12:08
Is the same as what Enabled=false
on serverside generates or Attributes["disabled"]="disabled"
does. But it apparently doesn't work for other browsers than IE with links (anchor tags): <a href="#" id="button" disabled="disabled">this is not disabled in FF</a>
- Tim Schmelter
No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas c# asp.net or haz tu propia pregunta.
you do it in javaScript or on server side? - Harry89pl
What is the generated html source code of this object? - Reporter
For what? as @harry180 said it shell be better to make it with js - cnd