FarizHuseynli FarizHuseynli - 2 months ago 20x
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;


You should use onKeyPress event to call the function.

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