I've designed a GUI where I want to enable a button depending on the contents of an asp:textbox.
If the textbox is empty, the button should be disabled, and if there is text in the textbox, the button should be enabled.
I've tried using the code behind textbox textchanged event, which works, but it only works after the textbox loses focus.
I've tried hooking up onKeyDown...
Where t1 is the textbox, and a1 is the button to enable/disable.
The javascript...
The javascript method works great for adding text, but when using backspace or delete, the enable/disable code doesn't work if the textbox is empty...
Any pointers here?
If the textbox is empty, the button should be disabled, and if there is text in the textbox, the button should be enabled.
I've tried using the code behind textbox textchanged event, which works, but it only works after the textbox loses focus.
I've tried hooking up onKeyDown...
Code:
t1.Attributes.Add("onkeydown", "return handleKeyDown(t1, a1)")
The javascript...
Code:
function handleKeyDown(textbox, button)
{
button.disabled = (textbox.value.trim == "" || textbox.value == null);
return true;
}
Any pointers here?