Use the following JavaScript code. Wrap it in a
<script>
tag and place it on your
<head>
tag:
window.onload = function () {
var txt = document.getElementById("<%= yourTxt.ClientID %>");
var btn = document.getElementById("<%= yourBtn.ClientID %>");
if (txt.value === "") {
btn.style.visibility = "hidden";
}
txt.onkeyup = function () {
if (txt.value !== "") {
btn.style.visibility = "visible";
} else {
btn.style.visibility = "hidden";
}
};
};
When your page is loaded, it checks whether the textbox is empty, and if it is, it hides the button.
At
onkeyup
, the code checks whether there's text in the textbox. If yes, it shows the button, if no, it hides the button.