Pages

Wednesday, 3 July 2013

How To Enable or Disable a Controls Like Button, Textbox, Checkbox Using JavaScript in C# Asp.Net

How To Enable or Disable a Controls Like Button, Textbox, Checkbox Using JavaScript in C# Asp.Net


Program:

.Aspx File:

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Enable or Disable a control</title>
<script language="javascript" type="text/javascript">
    //function to enable button if two textboxes contains text
    function SetButtonStatus() {
        var txt = document.getElementById('txtfirst');
        //Condition to check whether user enters text in two textboxes or not
        if (txt.value.length >= 1)
            document.getElementById('btnButton').disabled = false;
        else
            document.getElementById('btnButton').disabled = true;
    }
</script>
</head>
<body>
<div>
<b>Enter Text:</b><input type="text" id="txtfirst" onkeyup="SetButtonStatus(this,'btnButton')"/>
<input type="button" id="btnButton" value="Button" disabled="disabled" />
</div>
</body>
</html>

Live Demo:

Enable or Disable a control
Enter Text:

No comments:

Post a Comment