Click here to Skip to main content
12,955,493 members (68,892 online)
Click here to Skip to main content
Add your own
alternative version


94 bookmarked
Posted 23 Jun 2002

Simple User Account Login

, 23 Jun 2002
Rate this:
Please Sign up or sign in to vote.
Demonstrates maintaining user account information, managing session state, Access database I/O, cookies, and some other basic features.

Sample Image - UserAccountLogin.jpg


This is a simple demonstration of managing user account information on a server using ASP.NET. I decided that this might be a good way to get my feet wet in the whole ASP.NET environment, and the trials that I went through to get this far, might be of interest (and amusement!) to everyone else.

I am very much indebted to the numerous people on CP, who have helped answer some of my very basic questions. You all know who you are, and I thank you very much for your help.


This project demonstrates the use of:

  1. Managing username, password, and configuration options in an MS Access database;
  2. Using HttpResponse.Cookies and HttpRequest.Cookies to remember the user's login name;
  3. Use of HttpSessionState to retain the user ID between web pages
  4. Some simple JavaScript to set the focus of controls on the web pages

The Journey into ASP.NET land

While embarking on this journey, I encountered a variety of "interesting" problems to solve. What follows are my notes regarding the things I learned.

HTML Controls

I wanted to use the HTML password control for passwords, since it displays "dots" for the password text. I couldn't find any web form control that did this. I'm used to the MFC edit box which has a password style. It doesn't seem that the web form edit control has this capability. I could be wrong! In any case, using HTML controls is interesting because to do anything useful with the control in the C# text, you have to convert it into a "server control", which is accomplished quite easily by right clicking on the HTML control and selecting "run as server control". Of course, it took about an hour to figure this out!

Tab order

After I set up my first login screen, I noticed the tab order was wrong. So, silly me, I went looking around the IDE for a "tab order" wizard or menu command like the one for MFC. I couldn't find it! So, instead, I moved the controls around directly in the HTML. That was fairly straight forward. Later on, I discovered the TabIndex property for control. But, since I had my controls all ordered correctly in the HTML by then, I never played with the TabIndex. Personally, I'd rather get them ordered right in the HTML.

Setting the Control ID

It's most helpful if you set the ID's of the web form control first, before creating event handlers. Otherwise, you'll end up with some non-descript name and you'll have to edit the box titled "Web Form Designer generated code" to change the names of the event handlers, etc. Not too painful, but doing it right the first time is very helpful.

Centered Labels

I had an interesting time of getting the "Welcome to my web site" text centered to the size of the panel. I couldn't find a way to center justify the web form label control, so I created an HTML label, set it as "Run As Server Control", then changed the style, etc. Is there a better way?

An annoying thing

The thing that's annoying about these HTML controls is that the method for setting text is different. For example, label text has to be set with the InnerText method, while edit box text is set with the Value method. The inconsistency makes life for beginners harder.

Databases and folder permissions

I pulled my hair out for about a day trying to figure out why I could query the database, but I couldn't update it. A friendly Code Project member replied to my message and pointed out that I needed to put the database into a separate folder that had read/write permission (among other things, so that the .LDB file could be created). I had been playing with permissions in the IIS to no avail. Doing this made everything work, except that originally, my password field was called PASSWORD, which worked fine in queries but not updates.

State, Persistence, and Server vs. Client

I must say, this whole web form stuff being stateless is quite an interesting thing to deal with. You really have to change the style in which you program, and therefore, think, about persistence, etc. Also, I'm learning that I have to segregate my thinking into server vs. client side functionality. So, for example, I was trying to figure out how to set the focus to the user name edit control using a server side method. Posing this question on CP provided me with the answer that, this is a client side thing to do. A code example was kindly provided.

As a veteran MFC/C++ programmer, even having segregated client vs. server database functionality, I find it very hard to create a mental image of what happens on the server and what happens on the client. I think this confusion is aided by the fact that ASP.NET makes this line fuzzier, with event handlers, etc.


I'm not going to do any code snippets here (unless requested). You can peruse the code yourself by downloading the project. It's quite straightforward. All of the code is more or less copied out of the MSDN help and the excellent .NET Framework Essentials from O'Reilly Press, and of course from numerous posts on CP. I've just glued it all together to make a simple demonstration and added some prototypes of classes that might be useful to me later on.

If anyone is interested in some controversial stuff, you can read my comments in the code about how I implemented the database interface. Don't look for encryption on the passwords or a lot of other bells and whistles. This is intended to be a demonstration program only, something of a test-bed as I get by ASP.NET, feet wet.



This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


About the Author

Marc Clifton
United States United States
Marc is the creator of two open source projects, MyXaml, a declarative (XML) instantiation engine and the Advanced Unit Testing framework, and Interacx, a commercial n-tier RAD application suite.  Visit his website,, where you will find many of his articles and his blog.

Marc lives in Philmont, NY.

You may also be interested in...

Comments and Discussions

QuestionHai getting parsing error.. <%@ Application Codebehind="Global.asax.cs" Inherits="Account.Global" %> Pin
Soorajth9-Feb-09 18:02
memberSoorajth9-Feb-09 18:02 
GeneralRegistration and Log In Pin
vbconcepts22-Apr-08 6:41
membervbconcepts22-Apr-08 6:41 
GeneralRe: Registration and Log In Pin
mauji11-Jul-09 21:38
membermauji11-Jul-09 21:38 
GeneralLogin problem Pin
kidus12-Oct-07 8:16
memberkidus12-Oct-07 8:16 
GeneralLogin.html Pin
kaushik.mota17-Dec-05 7:56
memberkaushik.mota17-Dec-05 7:56 
GeneralI'v got error plase Help!!! Pin
AngleBkk7-Jul-05 5:17
memberAngleBkk7-Jul-05 5:17 
GeneralRe: I'v got error plase Help!!! Pin
lauralucas29-Jun-06 10:18
memberlauralucas29-Jun-06 10:18 
GeneralRe: I'v got error plase Help!!! Pin
crop47-Sep-06 5:48
membercrop47-Sep-06 5:48 
GeneralGetting a Parse Error Pin
webdinamico23-Jan-05 9:15
memberwebdinamico23-Jan-05 9:15 
GeneralRe: Getting a Parse Error Pin
kerberos_prozac30-Mar-05 13:45
memberkerberos_prozac30-Mar-05 13:45 
Generalbetter way Pin
idishkov14-Apr-04 22:11
memberidishkov14-Apr-04 22:11 
Generalaj aj aj poor coder Pin
idishkov214-Apr-04 22:04
sussidishkov214-Apr-04 22:04 
Generalhorrible Pin
zoelopital2-Oct-03 5:03
memberzoelopital2-Oct-03 5:03 
GeneralRe: horrible Pin
Marc Clifton2-Oct-03 5:20
editorMarc Clifton2-Oct-03 5:20 
GeneralRe: horrible Pin
Oggmanski2-Oct-03 9:08
sussOggmanski2-Oct-03 9:08 
GeneralRe: horrible Pin
Marc Clifton2-Oct-03 9:17
editorMarc Clifton2-Oct-03 9:17 
GeneralRe: horrible Pin
Joel Koblich21-May-05 17:38
memberJoel Koblich21-May-05 17:38 
GeneralSession state Pin
jmathew5-Jul-03 11:34
memberjmathew5-Jul-03 11:34 
GeneralBasics, very basics Pin
jgmata23-Jun-03 6:30
memberjgmata23-Jun-03 6:30 
GeneralUsing information Pin
kellyho6714-Jan-03 11:54
memberkellyho6714-Jan-03 11:54 
GeneralTabIndex property doesn't work. Pin
Phillip H. Blanton17-Dec-02 9:33
memberPhillip H. Blanton17-Dec-02 9:33 
GeneralGood article Pin
LaMagra26-Aug-02 23:16
memberLaMagra26-Aug-02 23:16 
General"Operation must use an updateable query." Pin
Sasha Djurovic3-Jul-02 12:34
memberSasha Djurovic3-Jul-02 12:34 
GeneralRe: "Operation must use an updateable query." Pin
Sasha Djurovic3-Jul-02 13:13
memberSasha Djurovic3-Jul-02 13:13 
GeneralRe: "Operation must use an updateable query." Pin
Anonymous28-Jul-02 18:58
sussAnonymous28-Jul-02 18:58 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web01 | 2.8.170525.1 | Last Updated 24 Jun 2002
Article Copyright 2002 by Marc Clifton
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid