¿Cómo deshabilitar el botón en el evento de clic?

Following code is not working in IE.I need to fix this in chrome,fire fox and IE

 button.Attributes["disabled"] = "disabled";

preguntado el 28 de agosto de 12 a las 12:08

you do it in javaScript or on server side? -

What is the generated html source code of this object? -

For what? as @harry180 said it shell be better to make it with js -

3 Respuestas

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

 button.Attributes.Add("disabled", "true"); 

Respondido 28 ago 12, 13:08

Ohk..try now..I have made some changes. - ygssoni

$('#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 or haz tu propia pregunta.