Monday, March 26, 2012

AJAX AutoCompleteExtender

Hi, I'm a newbie to the AJAX tool kit.

I have few basic questions.

1) Is it necessary to have a webservice running to get the data from the data base.. My question is, assume i have a list of Employee names.As soon as i started typing in the Text Field i need to display the Employee name. I have seen a Video session on this. but do we exactly need to run the webservice which has data base conection and retrieval from the database?

2) is it sufficient to have a method to get the data from DB in the .cs file.

Suggest me the Best one.

Tell me a best practise link where i can learn them from basics...

Thanks,

Mythily

Hi Mythily,

No, you have an alternative option, PageMethod. This is a static method defined in the page itself and can be accessed from client side directly.

For example:

// this method is defined in the page itself
[System.Web.Services.WebMethod]
[System.Web.Script.Services.ScriptMethod]
public staticstring[] GetCompletionList(string prefixText, int count)
{
string[] words = prefixText.Split(new char[] { ';' });
string[] result = new string[16];
for (int i = 0; i < 16; i++)
{
result[i] = "aaaa";
}
return result;
}

<ajaxToolkit:AutoCompleteExtender CompletionSetCount="4" CompletionListCssClass="completeListStyle" BehaviorID="ace" ID="AutoCompleteExtender1"ServicePath="AutoCompleteExtender.aspx" ServiceMethod="GetCompletionList"runat="server" TargetControlID="TextBox1">

Hope

No comments:

Post a Comment