我正在使用Ajax Autocomplete查找學生姓名並返回學生ID。我的更新面板看起來是這樣的:查找包含AutoCompleteExtender的UpdatePanel的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的ID( StudentSearchUpdatePanel),所以我可以依次找到「StudentIDTextBox」並將選擇的學生ID放入StudentIDTextBox.innerHTML中。 如何識別StudentIDTextBox並將其設置爲selected_Student的innerHTML?
(學生類是ID,FirstName,LastName。我已經驗證了selectedStudent.ID提供了一個acurate id)。
感謝
myTextbox.innerText = student.ID有效!謝謝。 – Jazzy