views:

78

answers:

1

Looking for guidance on how to achieve something in ASP.NET Web Form - the behaviour is a bit like that seen in ASP.NET AutocompleteExtender, but I can't find anything that gives the flexibility I need. Here is what I am trying to do:

  • 2 TextBox fields on the form, CompanyName and CompanyRef (CompanyRef an abbreviated unique Company identifier)
  • User types in the CompanyName
  • As soon as there are 3 characters in the CompanyName an internal webservice is called (AJAX?)
  • Webservice checks what has been entered so far and evaluates a 3 character representation of it - for instance "Stack" would be returned as STA0001.
  • If there is already an STA0001 in the db it would return STA0002 and so on
  • The value returned would be targetted at the CompanyRef TextBox
  • User needs to be able to edit the CompanyRef if they so wish

I'm not looking for code per se, more high level guidance on how this can be done, or if there are any components available that I am missing that you may be able to point me in the direction of. Googling and searching on SO has returned nothing - not sure if I'm looking for the right thing though.

+1  A: 

Generating the CompanyRef is easy enough. There are lots of articles etc which cover combining say an autonumber or counter with a string. The difficulty I have with your approach is that you intend to let users fiddle with the ref, and make their own up. What for?

[EDIT - Follow up to comment]

The comment box didn't allow for enough characters to answer your comment fully (and I'm still getting used to the conventions in place here....)

You could use AJAX to call the web service and return currently available values, and then use javascript to update the field. The problem with this is that once a user has decided he or she likes one, it may no longer be available when it is passed back to the database. That means you will have to do one final check, which may result in a message to the user that they can't now have the value they were told was available when they started the process. Only you know the likelihood of this happening. It will depend on the number of concurrent users you have.

I've done an article on calling web services etc using jQuery which should give you a starting point for the AJAX part: http://www.mikesdotnetting.com/Article/104/Many-ways-to-communicate-with-your-database-using-jQuery-AJAX-and-ASP.NET

MikeB
The automated function is supposedly convenience as 80-90% of users won't care what the reference is, but the data can be exported and passed to third parties for analysis - the user may want to apply some sort of grouping to the reference etc. The main bit I am struggling with is how you make this happen at the front end - ie how do I get the edits in one text field generate the value in another field based on the response from a webservice
Chris
See the edit I made to my original answer
MikeB
Excellent - thanks.
Chris