I have a Jquery autocomplete ajax function whose source is calculated from code behind. however I am getting the source in javascript using client script manager but my function doesn’t execute.
Apart from that I am trying to call that ajax function from code behind through
ClientScriptManager.RegisterStartupScript()
But again my function doesn’t execute.
My function is:
<form id="form1" runat="server">
<div>
<input id="Text1" type="text"/>
<input id="Text2" type="text" /><br />
<br />
<input id="Button2" type="button" value="button" />
<script type="text/javascript">
var mydataformat = [{ label: "....", value: "....", icon: "....." },
{ label: "....", value: ".....", icon: "....." }];
$(function() {
$("#Text1").autocomplete({
minLength: 0,
source: JSVar,
focus: function (event, ui)
{
$("#Text1").val(ui.item.label);
return false;
}})
.data("autocomplete")._renderItem = function (ul, item) {
return $("<li></li>")
.data("item.autocomplete", item)
.append("<a><img src='" + item.icon + "' width='32' height='32' /> " + item.label + "</a>")
.appendTo(ul);
};
});
</script>
You have to set the source when your data has been loaded like mentioned here:
…or better initialize your autocomplete when your calculated data is ready, not earlier.