I am using Ajax Autocomplete to look up student names and return the student ID. My update panel looks like this:
<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 looks like this:
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;
}
And finally, selected_student:
function selected_Student(sender, e) {
var selectedStudent = eval("(" + e._value + ")");
}
In selected_student I want to find the ID of the UpdatePanel (StudentSearchUpdatePanel) so I can in turn find “StudentIDTextBox” and place selectedStudent.ID in StudentIDTextBox.innerHTML.
How do I identify the StudentIDTextBox and set it’s innerHTML from selected_Student?
(the student class is ID, FirstName, LastName. I have verified that selectedStudent.ID gives an acurate id).
Thanks
An easier solution would be to make it easy to find the ID of the textbox you want if the first place.
One way of doing this would be to use
ClientIDMode="Static"on yourasp:TextBox. This will force the control of having the sameidattribute on the client as the server name for the control. That way, to find this control on the client (using JS), you would just:Hope that helps.