AutoComplete AJAX Control with Ajax.NET Professional
I have finished a more complex auto complete textbox you can use in you Ajax.NET Professional web application. The control can be added on the server like other HtmlControls:
AjaxAutoComplete textBox1 = new AjaxAutoComplete();
textBox1.ID = "hans1";
placeHolder1.Controls.Add(textBox1);
You have to specify where you want to get the data back. There is a delegate that must point to a public Ajax.NET method, i.e. like this:
textBox1.OnAutoComplete = new
AjaxAutoComplete.AutoCompleteHandler(this.OnAutoComplete);
The this.OnAutoComplete method looks like this:
[AjaxPro.AjaxMethod]
public object[] OnAutoComplete(string value, int count)
{
string[] s = new string[(value.Length < count ? value.Length : count)];
for(int i=0; i<s.Length; i++)
{
s[i] = value.Substring(0, i+1);
}
return s;
}
In a later version I will add the feature to override the render method to include more colums. The auto complete control is working with Internet Explorer and Firefox, other browsers have to be tested. You can download the source code at the Google group.
9 Comments
Comments have been disabled for this content.
roni said
hi michal,
have you also add this to the samples?
kind regards,
roni
Michael Schwarz said
Sorry, not yet, but I will do some work on the examples this evening and put the files online.
CIAO
Michael
Nick Clarke said
I like the way that you have implemented it.
Having a little error when running it :( (posted to google groups).
I'm one step closer as I need multile columns :) now that I have the autocomplete field.
Thanks,
Nick
Michael Schwarz said
Multiple columns, nothing easier than this!!! I will add an example...!
Alvin said
Hi, Michael
I am experiencing problem using the AUtoComplete TextBox.
I have added the code as below:
private void Page_Load(object sender, System.EventArgs e)
{
AjaxAutoComplete txt = new AjaxAutoComplete();
txt.ID = "txtAutoComplete";
txt.OnAutoComplete = new AjaxAutoComplete.AutoCompleteHandler(this.OnAutoComplete);
PlaceHolder1.Controls.Add(txt);
}
Likewise, I have the Ajax-method OnAutoComplete in my code-behind, reference the AjaxPro.dll.
But whenever I typing a character in the textbox, it showed javascript error.
"Line : 105
Char : 3
Error : Undefined is nullor not an object
Code : 0"
FYI, the code at line 105 is
"o[this.method](this.control.value, this.count, this.callback.bind(this));"
Could you tell me what is the problem ? Am I missing something ? THanks ! :)
karl said
Any idea why I get an:
Sorry...
You don't have sufficient permissions to view this page.
when I try to click on the .cs file?
karl said
funny, I was able to get it from a different computer....oh well, got it now, :)
Ian Noble said
I'm also getting the:
"Line : 105
Char : 3
Error : Undefined is nullor not an object
Code : 0"
FYI, the code at line 105 is
"o[this.method](this.control.value, this.count, this.callback.bind(this));"
Has anyone resolved this issue? Thanks!!
Gabriel E said
I'm also getting the:
"Line : 105
Char : 3
Error : Undefined is nullor not an object
Code : 0"
FYI, the code at line 105 is
"o[this.method](this.control.value, this.count, this.callback.bind(this));"