I'm a bit of a newbie to ASP.NET, but I'm pretty decent at C#. I find this approach very easy in PHP, but it's a lot different in ASP.NET.
My problem is that I don't know how to query ASP.NET functions from jQuery. I have an ASP.NET WebForms project, and the code-behind (TestMe.aspx.cs) contains the following code:
[WebMethod]
internal List<string> GetSearchSuggestions(string SearchQuery)
{
string ConnectionString = "Data Source=<omitted>;Initial Catalog=<omitted>;Integrated Security=True";
string TSQL_Query = "<omitted>";
List<string> SearchSuggestions = new List<string>();
using (SqlConnection connection = new SqlConnection(ConnectionString))
using (SqlCommand command = new SqlCommand(TSQL_Query, connection))
{
connection.Open();
System.Data.SqlClient.SqlDataReader r = command.ExecuteReader();
while (r.Read())
{
SearchSuggestions.Add(r.GetString(0));
}
}
return SearchSuggestions;
}
And I have this function in the same file (TestMe.aspx.cs):
protected void tb_SearchQuery_TextChanged(object sender, EventArgs e)
{
string Input = SanitizeInput(this.tb_SearchQuery.Text);
if (!String.IsNullOrEmpty(Input) && Input.Length > 1)
{
Response.Write("<ul>");
foreach (string item in GetSearchSuggestions(Input))
{
Response.Write("<li>" + item + "</li>");
}
Response.Write("</ul>");
}
}
Now, this DOES produce results, but only after clicking the textbox button. I want to make this appear automatically as the user types.
How do I do that?
Thanks!