[ Download Source Code ]
Introduction
One of the strengths of ASP.NET is the ease with which developers can create custom web server controls. If you find yourself repeatedly adding the same code across pages or across applications, you should consider creating a custom server control.
If you create websites that require users to log in, then you are sure to have repeated the code needed to obtain a user's username and password. This is a prime candidate for a custom server control.
In this article we will cover the details of developing a customizable Login control that you can add to your Visual Studio .Net toolbox, which can then be added to any ASP.NET Web Form with a simple drag and drop action. The Login control has a set of useful features that we will cover in the different sections of this article.
Outline
In this article, we will start by outlining the various features of the Login control, and then look in depth at the code behind building that control. Finally, we will present an example of how to use the Login control on an ASP.NET Web Form.
Login Control Features
The Login control that we will create is a customizable control, in the sense that it contains many features that can be turned on or off according to the developer's preference. The appearance of the control is also customizable through the use of CSS.
To start with, the Login control has the following basic content:
-
A UserName TextBox, to hold the username.
-
A Password TextBox, to hold the password.
-
An Error Label, to show any error generated upon a login failure.
The above controls are the basic contents of the Login control. Its customizable features are:
-
A Remember Me CheckBox, to give the user the option to have a persistent cookie of his login.
-
A Create New Account HyperLink, to link to the page where a user can create a new account.
-
A Forgot Password HyperLink, to link to the page where a user can retrieve his password.
The above features will be presented in detail in the following sections.