Encapsulate Web Forms Code
Learn how to create Web user controls that handle login checking for your .NET Web pages.
by Stan Schultes
The .NET environment's most useful category of new technology is arguably its Web development tools, especially the Web Forms technology. Web Forms incorporates the event-driven programming model that Visual Basic made popular. You can now build a Web app with event routines that respond to actions a user makes on a Web page, much as you would with a traditional VB program.
VB.NET, SQL Server 2000, ASP.NET, Windows 2000 Server for Web server, Workstation for development
Note: Also works with SQL Server 7.0 and Access 97/2000/XP
I'll show you how to build a pair of Web user controls to add custom login functionality to your .NET Web applications. Web user controls are reusable bits of Web page functionality that you build into a special class file with an ASCX extension. Essentially, these controls are the contents of a Web form without the opening and closing form tags (<form> and </form>), which are part of the Web Forms page itself. You drop the user control onto a Web form, and it becomes a subset of the form's functionality.
The sample code for this column consists of two Web user controls: loginCheck and loginControl. The loginCheck control is an invisible control that checks whether the user has logged in and if not, it redirects the user to the login page; you place the control on any Web page you want to protect with a user login. The loginControl Web control provides the user interface for your login page and allows access to the protected page once the user logs in successfully. You choose from two login modes with loginControlby e-mail address with a common password (the same for everyone logging in), or by username with a private password you assign to each user in advance.
Start by running the VS.NET Integrated Development Environment (IDE). You can build any .NET project without the IDE, but for this project, I'll assume you have VS.NET. If you've never used VS.NET before, you'll begin at the Start page, which allows you to customize your VS profile by setting the keyboard scheme, screen layout, and other startup options. If you're a VB6 programmer, you might want to choose the VB6 keyboard layout and use the Visual Studio default window layout.
Back to top