0
votes

I have a requirement that is when user entering text in the textbox i want to show a message (not alert box, this is asp: lable) i.e if user enter "x" in the textbox then i want show a message not after completion of text and not like ontextchanged event. If user cleans textbox then i don't want to show message.

2
Are you saying you want to use the keypress event? I.e., on each keystroke check the current value of the field and decide what (if any) message to display within another element? - nnnnnn
can u be more clear? what kind of message? - CRDave
I want to show <asp:lable> message<asp:lable> i can use onkeypress event but if user clears text box message not hidding and if user press space and escape buttons also showing message. - Indra

2 Answers

0
votes

You may try something like this:

Your textbox:

<asp:TextBox ID="TextBox1" runat="server" onKeyUp="my_function(this);"></asp:TextBox>

where your function my_function() is defined as follows:

<script type="text/javascript">
    function my_function(el) {
        var val = this.value;
        if(val && val!="") {
            // Hide your message
            // ....

        } else {
            // Show your message
            // ....

        }
    }
</script>

Hope this helps

0
votes

you can use one of following three javascript events what ever suits you best,
onkeydown
onkeypress
onkeyup
to understand difference between these events refer to this link

http://www.bloggingdeveloper.com/post/KeyPress-KeyDown-KeyUp-The-Difference-Between-Javascript-Key-Events.aspx