my problem is that i user control have 2 controls
1- text box with autocomplete function
2- label control which get id of autocompelte value
when i select value of autocomplete it replace all labels values. even wich textbox empty. my issue is label value
<%@ Control Language="C#" AutoEventWireup="true" CodeFile="WebUserControl.ascx.cs" Inherits="WebUserControl" %>
Enter search term:
<asp:TextBox ID="txtSearch" runat="server" />
<asp:Label ID="lbl_id" runat="server" Text="ID"></asp:Label>
<script src="https://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.10.0.min.js" type="text/javascript"></script>
<script src="https://ajax.aspnetcdn.com/ajax/jquery.ui/1.9.2/jquery-ui.min.js" type="text/javascript"></script>
<link rel="Stylesheet" type="text/css" href="http://ajax.aspnetcdn.com/ajax/jquery.ui/1.9.2/themes/blitzer/jquery-ui.css" />
<script type="text/javascript">
//On Page Load.
$(function () {
SetAutoComplete();
});
//On UpdatePanel Refresh.
var prm = Sys.WebForms.PageRequestManager.getInstance();
if (prm != null) {
prm.add_endRequest(function (sender, e) {
if (sender._postBackSettings.panelsToUpdate != null) {
SetAutoComplete();
}
});
};
function SetAutoComplete() {
$("[id$=txtSearch]").autocomplete({
source: function (request, response) {
var id = $("[id$=txtSearch]:focus").attr('id').split('_')[0];
$.ajax({
url: '<%=ResolveUrl("~/WebService.asmx/") %>' + id,
data: "{ 'prefix': '" + request.term + "'}",
dataType: "json",
type: "POST",
contentType: "application/json; charset=utf-8",
success: function (data) {
if (!data.d.length) {
var result = [{ label: "no results", value: response.term }];
response(result);
}
else {
response($.map(data.d, function (item) {
return {
label: item.split('-')[0],
val: item.split('-')[1]
};
}))
}
},
error: function (d) { alert(d.responseText) }
});
},
select: function (e, i) {
var label = i.item.label;
if (label == "no results") {
$("[id$=lbl_id]").html("");
}
else {
$("[id$=lbl_id]").html(i.item.val);
}
},
delay: 0,
minLength: 1,
mustMatch: true,
autoFocus: true
});
}
</script>
above is usercontrol html code
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
<%@ Register Src="~/WebUserControl.ascx" TagName="Name" TagPrefix="uc" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<uc:Name ID="GetFruits" runat="server" />
<br />
<br />
<uc:Name ID="GetCountry" runat="server" />
</ContentTemplate>
</asp:UpdatePanel>
</form>
</body>
</html>
above is pagel aspx code
in usercontrol i want to set label on base of autocomplete but it set all label with same value