简体   繁体   中英

How can I stop a user that tries to enter a name instead of selecting from a list in AutoCompleteExtender? ASP.NET

Here's my situation: I'm programming using C# in ASP.NET and I use SQL Server for a database.

On this particular page, the code behind is done in VB (long story, the usual code behind is a .CS file but this is one of my earlier pages). I have users that enter the first few letters of a last name and then AutoCompleteExtender shows the rest of the names in the database with those starting letters. Not only that, it shows name and the person's unique ID number (this was done for a specific reason). The name and ID are separated using the delimiter "|" (ie Babbatt, Aaron | 9920).

IF the user doesn't click on one of the names (like they should), and just enter a name .. I need to create something in the code behind (in VB) that yells at the user because there's no unique ID number attached to the name. Basically, I don't want them to enter a name without selecting one on the list given in the database. As it currently is, if a user types in a random name and hits submit, it goes through to my database which I don't want. can I do this without utilizing the code behind in VB?

What's the best approach here? I'd prefer not to use a straight up SCROLL BAR because this page was designed for users to be able to enter data quickly and selecting from a massive list of names doesn't fit that criteria.

I'm stuck. Thanks for your help.

Rather than default to yelling at the user, you can check the name against your list and try to find a match. If it exists, use the matching ID, otherwise, report back that the user was not found.

This would be done as part of validation.

You can also see other suggestions here: Using the AutoComplete feature of ComboBox, while limiting values to those in the list?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM