1

I have an AutoCompleteExtender on a text box for Last Name, First Name, Unique ID.

I would like to make it so that users can only pick an item from the list and not type their own unique ID number. I can't use the AJAX ComboBox because the database I need to use is really large and I read that AutoCompleteExtender is best for use with large databases.

Any ideas how I could accomplish this? Javascript is the best option for me at this point. I'd prefer not to do it in the code behind. I've only found one example on this. I tried using an onblur="checkItemSelected(this)" with some Javascript but the problem is I am already using an onclientclick="alert('Your data has been SAVED!')" because this page is designed for a user to enter many names in the same screen and it's not cooperating.

Thanks so much for the help.

  • So how are you populating the ID box? Why cant you use a selectbox for it? If you cant type in it then whats the point of having a textbox? If your populating it based off of values from other input fields then it seems like you should consider a different control. – Colin Pear Dec 20 '12 at 13:44

1 Answers1

0

The best course of action turned out to be using a little Javascript onBlur in the text box that was using AutoCompleteExtender.

Here's the code:

var isItemSelected = false;

  //Handler for AutoCompleter OnClientItemSelected event
  function onItemSelected() {
      isItemSelected = true;
  }

  //Handler for textbox blur event
  function checkItemSelected(myTextBox) {
      if (!isItemSelected) {
          alert("Please select item from the list only!");
          myTextBox.focus();
      }
      else {
          //reset isItemSelected
          isItemSelected = false;
      }
  }

And then throw this in the Textbox:

onblur="checkItemSelected(this)"