Question: I have a login page where user enters Username(textbox), Password(textbox), and location(dropdownlist) then login. 

On the server page, for the location dropdonwlist I have a connection string to access SQL server database to get all locations from location table and bound the data to the dropdownlist. 

For the dropdownlist.SelectedItem, What I want to do is that once user enters Username, onChange, the default location for the particular user should be the selected location before the user clicks Login. This default location is defined by locationID(FK) in the Login table which has loginId, username, password, and locationID as its columns. I want the process of retrieving locationID (accessing a DB table) to happen on the server side, then pass the locationID to the client side where I can call a function to select a default dropdownlist item according to the locationID. What's the way to accomplish this?? Thanks

Programming Language C#
Database SQL Server 2005

Answer: 
There are two ways to get this done: AJAX or Postback. AJAX would be the nicer way and postback would be the easier way, it's up to you really...

Both ways would take the username and run a query against the db to get the locationid and then select it from the dropdown.

Logically however this can be a security hole (unless running internally) where a hacker could generate random usernames and see if they return a valid location since a passwrod is not needed. Which leads me to question why you need to select a location if it's in the db already? You can just select it when validating the user...
Which is tied more closely to a 'location': the user or the computer?

If it's appropriate to pick a default location for a ***computer*** instead of a ***user***, 
you could consider using a cookie to store the default location. Some advantages:

* No javascript required - Drop down default is selected by the server.
* Single request - The cookie value is included in the GET request.

It would be relatively easy to implement with some caveats:

* A cookie is scoped to the client computer's (windows) user account. If you have two users on the same computer (as same user) with different locations, then this isn't a good solution.
* Sometimes browsers have cookies turned off.