Hi MohmdNader,
You can try below link if no result will found so you can clear the textbox value on click of no result found. If by mistake you spell wrong then you need choice to correct it.
If you want to clear directly if no any result match when you input any value then just modify above link code with below code.
<script type="text/javascript">
$(function () {
$("#txtSearch").autocomplete({
source: function (request, response) {
$.ajax({
url: 'CS.aspx/GetFruits',
data: "{ 'prefix': '" + request.term + "'}",
dataType: "json",
type: "POST",
contentType: "application/json; charset=utf-8",
success: function (data) {
if (data.d.length > 0) {
response($.map(data.d, function (item) {
return {
label: item.split('-')[0],
val: item.split('-')[1]
};
}))
} else {
//If no records found, set the default "No match found" item with value -1.
//response([{ label: 'No results found.', val: -1}]);
$('#txtSearch').val("");
$("#<%=lblFruit.ClientID %>").html("");
}
}
});
},
select: function (e, u) {
$("#<%=lblFruit.ClientID %>").html(u.item.value);
}
});
});
</script>
Enter search term:
<input type="text" id="txtSearch" />
<asp:Label ID="lblFruit" Text="" runat="server" />
Screenshot