Quantcast
Channel: VBForums
Viewing all articles
Browse latest Browse all 15038

[RESOLVED] asp:textbox need realtime textchange

$
0
0
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...

Code:

t1.Attributes.Add("onkeydown", "return handleKeyDown(t1, a1)")
Where t1 is the textbox, and a1 is the button to enable/disable.
The javascript...

Code:

function handleKeyDown(textbox, button)
{
  button.disabled = (textbox.value.trim == "" || textbox.value == null);
  return true;
}

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?

Viewing all articles
Browse latest Browse all 15038

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>