FarizHuseynli FarizHuseynli - 1 year ago 226
ASP.NET (C#) Question

ASP textbox calls javascript function

I have a search textbox in asp. And I want it to send request to the server each time the text is changed there. I have a javascript function which sends request but it is not being called each time when I type something in the text box. How can I call javascript function from ASP textbox?

That is my textbox:

<asp:TextBox ID="search" name="Search" runat="server" onchange="javascript:text_changed();"></asp:TextBox>

That is my js function:

function text_changed() {
searchedword = document.getElementById("ContentPlaceHolder1_search").value;

Answer Source

You should use onKeyPress event to call the function.

<asp:TextBox ID="search" name="Search" runat="server" onKeyPress="javascript:text_changed();"></asp:TextBox>
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download