Link to home
Start Free TrialLog in
Avatar of Tomazaz
Tomazaz

asked on

TextBox.OnTextChanged fire on typing

Hello,

As we know TextBox.OnTextChanged event do not fired when text is typed, TextBox must lose focus or ENTER key must be pressed in TextBox to execute OnTextChanged.

Maybe someone could suggest hack how to execute OnTextChanged event on typing?

Regards,
Tomas
ASKER CERTIFIED SOLUTION
Avatar of nmarun
nmarun
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
in jQuery it is very simple with keydown
http://docs.jquery.com/Events/keydown
Avatar of Tomazaz
Tomazaz

ASKER

I never used jQuery and even not imagine how to integrate and how it can help me in my situation, do you have example?
here is a quick working example - jQuery is a great tool that is very versatile and has a huge community with lots of tutorials
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
 
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title></title>
    <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.1/jquery.min.js"></script>
    <style type="text/css">
        div { padding:10px;margin:5px;border:solid 5px navy;}
    </style>
    
    <script type="text/javascript">
        $().ready(function() {
            $("#txtDemo").keydown(function(event) {
                $("#display").html($("#txtDemo").val());
            });
        });
    </script>
    
</head>
<body>
    <div>
        This is a demo using jQuery, you can load it locally, or call it from a code library (this demo is using Google's copy).
    </div>
    <div>
        Type something in this textbox, and it will show up in the next div:<br />
        <input type="text" id="txtDemo" /><br />
        This is using the jQuery keydown() function you can see in the &lt;head&gt; of this code
    </div>
    <div id="display"></div>
</body>
</html>

Open in new window

Avatar of Tomazaz

ASKER

nmarun, thank you, your links gave me idea.

So just added second ASP.NET event handler to OnKeyUp

edtValue.Attributes.Add('onkeyup', 'setTimeout(''__doPostBack(\''' + edtValue.UniqueID + '\'',\''\'')'', 0);');