AutoComplete AJAX Control with Ajax.NET Professional

Tags: .NET, AJAX, Ajax.NET, ASP.NET, JavaScript, Source Code

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

  • 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

  • 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 = &quot;txtAutoComplete&quot;;
    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.

    &quot;Line : 105
    Char : 3
    Error : Undefined is nullor not an object
    Code : 0&quot;

    FYI, the code at line 105 is
    &quot;o[this.method](this.control.value, this.count, this.callback.bind(this));&quot;

    Could you tell me what is the problem ? Am I missing something ? THanks ! :)

  • Ian Noble said

    I'm also getting the:

    &quot;Line : 105
    Char : 3
    Error : Undefined is nullor not an object
    Code : 0&quot;

    FYI, the code at line 105 is
    &quot;o[this.method](this.control.value, this.count, this.callback.bind(this));&quot;

    Has anyone resolved this issue? Thanks!!

  • Gabriel E said

    I'm also getting the:

    &quot;Line : 105
    Char : 3
    Error : Undefined is nullor not an object
    Code : 0&quot;

    FYI, the code at line 105 is
    &quot;o[this.method](this.control.value, this.count, this.callback.bind(this));&quot;

Comments have been disabled for this content.