I have a textbox and a listbox that displays customer information. On page load my listbox populates just fine from a webmethod and shows in a ClientItemTemplate. I want to be able to call this webmethod from code-behind and repopulate the listbox based on what text is typed in the textbox (onkeyup). The problem is I keep getting the error "JavaScript runtime error: Object doesn't support property or method 'get_parent'"
Here is the server-side code:
<WebMethod()> _ Public Shared Function GetCustomers() As RadListBoxItemData() Dim data As DataTable = GetData("248") Dim result As New List(Of RadListBoxItemData)() For i As Integer = 0 To data.Rows.Count - 1 Dim itemData As New RadListBoxItemData() Dim FullName As String = data.Rows(i)("FName").ToString() & " " & data.Rows(i)("LName").ToString() itemData.Text = data.Rows(i)("CPhone").ToString() itemData.Value = data.Rows(i)("CPhone").ToString() itemData.Attributes.Add("FullName", FullName) itemData.Attributes.Add("Phone", data.Rows(i)("CPhone").ToString().Insert(0, "(").Insert(4, ") ").Insert(9, "-")) '--Determine opt-in icon Select Case data.Rows(i)("OptIn").ToString() Case -1 itemData.Attributes.Add("OptIn", "<img alt='Opted-In' src='images_zw/OptIn_OptedIn.png' />") Case 0 itemData.Attributes.Add("OptIn", "<img alt='Blocked / Opted-Out' src='images_zw/OptIn_Blocked.png' />") Case 1 itemData.Attributes.Add("OptIn", "<img alt='Pending Opt-In' src='images_zw/OptIn_Pending.png' />") Case 2 itemData.Attributes.Add("OptIn", "") End Select result.Add(itemData) Next Return result.ToArray() End Function
Here is my client-side code:
<script type="text/javascript"> function Generate() { var listbox = $find("<%= lstContacts.ClientID%>"); var result = PageMethods.GetCustomers(function (response) { response.forEach(function (listitem) { listbox.trackChanges(); listbox.get_items().add(listitem); listbox.commitChanges(); }); //listbox.insertItems(response); }); } </script> <div> <div><telerik:RadTextBox runat="server" id="txtSearch" AutoPostBack="False" onkeyup="Generate();" Text="248"></telerik:RadTextBox></div> <div> <telerik:RadListBox runat="server" ID="lstContacts" width="300" height="500" AutoPostBack="False"> <ClientItemTemplate> <div class="Search_Conversation_Container"> <div class="Search_OptIn"> #= Text # </div> </div> </ClientItemTemplate> <WebServiceSettings Path="testlist.aspx" Method="GetCustomers"></WebServiceSettings> </telerik:RadListBox> </div> </div>