Wednesday, January 4, 2012

Disable/Enable the UI Controls using JavaScript in Asp.Net


In Design  
  
<asp:CheckBox ID="chkEnable" runat="server" Text="Enable" onclick="MakeEnable()" />
<asp:TextBox ID ="txtName" runat="server"></asp:TextBox>  


In JavaScript

<script type="text/javascript" >
       function MakeEnable() {

           if (document.getElementById('<%= chkEnable.ClientID %>').checked) {
               document.getElementById('<%= txtName.ClientID %>').disabled = true;
           }
           else {
               document.getElementById('<%= txtName.ClientID %>').disabled = false;
           }
      }
 </script>

I hope this article will be very helpful to all. Thanks for reading this article.

“Keep reading and share the knowledge”  
“Grow more trees to save the Earth”
 

No comments:

Post a Comment