我正在使用 Ajax Autocomplete 来查找学生姓名并返回学生 ID。我的更新面板如下所示:
<asp:UpdatePanel ID="StudentSearchUpdatePanel" runat="server">
<ContentTemplate>
<dl>
<dt>Enter student ID:</dt>
<dd>
<asp:TextBox ID="StudentIDTextBox" runat="server" Wrap="False" MaxLength="6"></asp:TextBox>
<asp:Button ID="SelectStudentIDButton" runat="server" Text="Select" OnClick="SelectStudentIDButton_Click" />
<asp:Label ID="StudentIDEntryError" runat="server" Visible="false" Font-Bold="True" ForeColor="Red" Text="Please enter a 6-digit student ID number."></asp:Label>
</dd>
<dt>Or, begin typing student last name:</dt>
<dd><asp:TextBox ID="StudentNameSearchTextBox" runat="server"></asp:TextBox></dd>
</dl>
<ajaxToolkit:AutoCompleteExtender ID="StudentNameSearchTextBox_AutoCompleteExtender" runat="server"
TargetControlID="StudentNameSearchTextBox"
ServiceMethod="GetStudents"
OnClientPopulated="getStudents_Populated_Json"
OnClientItemSelected="selected_Student"
MinimumPrefixLength="2"
CompletionSetCount="20"
UseContextKey="True" >
</ajaxToolkit:AutoCompleteExtender>
</ContentTemplate>
</asp:UpdatePanel>
GetStudents_Populated_Json 看起来像这样:
function getStudents_Populated_Json(sender, e) {
var students = sender.get_completionList().childNodes;
for (var i = 0; i < students.length; i++) {
var student = eval('(' + students[i]._value + ')');
students[i].innerHTML = student.LastName + ' ' + student.FirstName;
}
最后,selected_student:
function selected_Student(sender, e) {
var selectedStudent = eval("(" + e._value + ")");
}
在 selected_student 中,我想找到 UpdatePanel (StudentSearchUpdatePanel) 的 ID,这样我就可以找到“StudentIDTextBox”并将 selectedStudent.ID 放在 StudentIDTextBox.innerHTML 中。如何识别 StudentIDTextBox 并将其设置为 selected_Student 的 innerHTML?
(学生班级是 ID、FirstName、LastName。我已经验证 selectedStudent.ID 给出了准确的 id)。
谢谢