Enable/Disable Button Based On Empty TextBoxes Using JavaScript
This is to validate the textbox to ensure whether 12 characters are entered. The target textbox control will be enabled only if 12 characters are entered.
Add this script to the page.
<script language="javascript" type="text/javascript">
function SetButtonStatus(sender, target)
{
if ( sender.value.length >= 12 )
document.getElementById(target).disabled = false;
else
document.getElementById(target).disabled = true;
}
script>
<asp:TextBox ID="txtText" runat="server" onkeyup="SetButtonStatus(this, 'btnButton')">asp:TextBox>
<asp:Button ID="btnButton" runat="server" Text="Button" Enabled="false" />
This JavaScript validates the textbox and enables the button only if the textbox contains 12 characters.