I want to resolve issue of length is null or undefined while setting Autocomplete Text Box in asp.net with c#. I am setting the autocomplete based on Database in a content page. I am getting the exception
"Microsoft JScript runtime error: 'd.length' is null or not an object" on entering data in the Textbox.
The textbox in which autocomplete required is designed as below:
<div class="ui-widget">
Enter SFTP FileName:
<asp:TextBox type="text" id="txtSearch" runat="server" class="autosuggest" >
</div>
What I have tried:
$(function () {
SearchText();
});
function SearchText() {
$(".autosuggest").autocomplete({
source: function (request, response) {
$.ajax({
type: "POST",
contentType: "application/json; charset=utf-8",
url: "AutoTB.aspx/GetAutoCompleteData",
data: "{'filename':'" + document.getElementById('MainContent_txtSearch').value + "'}",
dataType: "json",
success: function (data) {
if (data.d.length > 0) {
response($.map(data.d, function (item) {
return {
label: item.split('/')[0],
val: item.split('/')[1]
}
}));
}
else {
response([{ label: 'No Records Found', val: -1 }]);
}
},
error: function (result) {
alert("Error");
}
});
},
select: function (event, ui) {
if (ui.item.val == -1) {
return false;
}
$('#lblUserId').text(ui.item.val);
}
});
}