我正在尝试将自动完成jQuery的当前值发送到ASP上的HiddenField
隐藏场:
<asp:HiddenField ID="hidden" runat="server" />
当页面加载时我只将HiddenField值分配给某个TextBox:
Protected Sub PrepareSession(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Dim hid = hidden.Value
Requester_NumEmpleado_TB.Text = hid
是jQuery代码:
<script type="text/javascript">
$("document").ready(function() {
$("#Requester_NumEmpleado_TB").autocomplete({
source: 'Search_VB.ashx',
autoFocus: true,
select: function(event, ui) {
}
});
$("#<%=hidden.ClientID %>").val("20020177") //this works but i want to send the Autocomplete Value, not the "20020177"
});
</script>
这适用于硬编码值,但我想从自动完成中发送值,而不是“20020177”。我该怎么做?
答案 0 :(得分:0)
您需要做的就是检索select
回调中自动填充字段中的值,并将其分配给隐藏字段的值:
<script type="text/javascript">
$("document").ready(function() {
$("#Requester_NumEmpleado_TB").autocomplete({
source: 'Search_VB.ashx',
autoFocus: true,
select: function(event, ui) {
var autocomplete_value = $("#Requester_NumEmpleado_TB").val();
$("#<%=hidden.ClientID %>").val(autocomplete_value);
}
});
});
</script>