Hello,
I tried to build a small test page that has a autocompletebox bind to a web method in the code behind of the page.
I copied the example from the autocompletedemo page, but I got this error : "The server method 'GetCompanyNames' failed."
There is a snippet of my code:
Code behind:
Thank you for your help,
Kind regards,
Oren Yardeni.
I tried to build a small test page that has a autocompletebox bind to a web method in the code behind of the page.
I copied the example from the autocompletedemo page, but I got this error : "The server method 'GetCompanyNames' failed."
There is a snippet of my code:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
<!DOCTYPE html>
<
html
xmlns
=
"http://www.w3.org/1999/xhtml"
>
<
head
runat
=
"server"
>
<
title
></
title
>
</
head
>
<
body
>
<
form
id
=
"form1"
runat
=
"server"
>
<
telerik:RadScriptManager
runat
=
"server"
></
telerik:RadScriptManager
>
<
telerik:RadAjaxPanel
runat
=
"server"
ID
=
"RadAjaxPanel1"
>
<
div
>
<
fieldset
style
=
"width: 400px"
>
<
legend
>Web service binding</
legend
>
<
label
for
=
"RadAutoCompleteBox2"
>
Company Names:</
label
>
<
telerik:RadAutoCompleteBox
runat
=
"server"
ID
=
"RadAutoCompleteBox2"
Width
=
"250"
DropDownHeight
=
"150"
DropDownWidth
=
"250"
>
<
WebServiceSettings
Path
=
"Defualt.aspx"
Method
=
"GetCompanyNames"
/>
</
telerik:RadAutoCompleteBox
>
<
p
>
<
asp:Label
runat
=
"server"
ID
=
"Label2"
/>
</
p
>
</
fieldset
>
</
div
>
</
telerik:RadAjaxPanel
>
</
form
>
</
body
>
</
html
>
Code behind:
using
System;
using
System.Collections.Generic;
using
System.Linq;
using
System.Web;
using
System.Web.Services;
using
System.Web.UI;
using
System.Web.UI.WebControls;
using
Telerik.Web.UI;
public
partial
class
_Default : System.Web.UI.Page
{
protected
void
Page_Load(
object
sender, EventArgs e)
{
}
[WebMethod]
public
AutoCompleteBoxData GetCompanyNames(
object
context)
{
string
searchString = ((Dictionary<
string
,
object
>)context)[
"Text"
].ToString();
List<AutoCompleteBoxItemData> result =
new
List<AutoCompleteBoxItemData>();
AutoCompleteBoxItemData childNode =
new
AutoCompleteBoxItemData();
childNode.Text =
"aaaa"
;
childNode.Value =
"aaaa"
;
result.Add(childNode);
AutoCompleteBoxData res =
new
AutoCompleteBoxData();
res.Items = result.ToArray();
return
res;
}
}
Thank you for your help,
Kind regards,
Oren Yardeni.