Introduction:
In this article you
will come to know Enable/Disable Asp.net server Controls using Javascript.
Following JavaScript is used to Enable/Disable Server Controls:
<script language="javascript" type="text/javascript">
function SetButtonStatus()
{
var txt =
document.getElementById('txtTextBox');
if (txt.value.length
>= 1)
document.getElementById('btnsubmit').disabled = false;
else
document.getElementById('btnsubmit').disabled = true;
}
</script>
|
Implementation:
Add a new webform
and design the .aspx page as shown below:
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<script language="javascript" type="text/javascript">
function SetButtonStatus()
{
var txt =
document.getElementById('txtTextBox');
if (txt.value.length
>= 1)
document.getElementById('btnsubmit').disabled = false;
else
document.getElementById('btnsubmit').disabled = true;
}
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:TextBox ID="txtTextBox" runat="server"onkeyup="SetButtonStatus(this,'btnsubmit')"></asp:TextBox><asp:ButtonID="btnsubmit" runat="server" Text="Submit" />
</div>
</form>
</body>
</html>
|
0 comments:
Post a Comment