I used an asp:Textbox as a search box on the ascx page. Now it works when I press enter after inputting my text. I want to change it to smart search. (when I press a key, the OnTextChanged should call to code behind the function without clicking anywhere or pressing enter key)
please help me to achieve this. Thank you
<asp:TextBox ID="SearchBox" runat="server" placeholder="Search" AutoPostback="true" OnTextChanged="SearchBox_TextChanged" ></asp:TextBox>
code behind in ascx page:
protected void SearchBox_TextChanged(object sender, EventArgs e)
{
// searching
}
you can use the onkeyup event of the TextBox to call JavaScript function which makes AJAX request to the server to perform the search, to do so, add
to your TextBox:
Then call the
function
Javascript:
and finally perform your search in server side and return result:
C#: