Im trying to implement an asp.net textbox using the jQuery UI Autocomplete widget http://jqueryui.com/demos/autocomplete/#remote.
The source property of the widget expects a string to point to a URL resource that will return JSON data. I have an aspx page that will return the following:
Code Behind:
private void GetWidgets(string name)
{
var jscriptSerializer = new JavaScriptSerializer();
var widgets = jscriptSerializer.Serialize(GetMatchingWidgets(name));
var script = "Widgets = {\"Widget\": " + widgets + "};";
Page.ClientScript.RegisterStartupScript(Page.GetType(), "JSON", script, true);
}
Questions:
- The documentation says the
The request parameter "term" gets added to that URL.— I should therefore be able to get the “term” as a query string parameter correct? - Do I have to set the JSON to a variable on the client or does the widget take care of the binding without having to do anything else?
Am I missing anything else?
I would give this a try and just “figure it out” but I don’t have a whole lot of time to spend on this solution.
Help is always appreciated.
Yes,
termis the name of the QueryString parameter. All you need to do is return json data in the expected format. For example, here is the class I use…for example…