Friday, March 21, 2008

While ASP.NET has been a boon to developers and web application projects alike, it stands to reason that several "classic" ASP applications are still out there needing support and updating. I can speak from experience. I have a very large application that will remain an ASP application for many years to come. The cost-benefit ratio just doesn't justify migrating this application to ASP.NET. That doesn't mean that you can't take some steps to spice up those applications and give them similar features to ASP.NET applications. Here are a few tips to do just that.

Use JavaScript for Form Validation

When the first ASP applications were launched, developers couldn't count on the availability of JavaScript to perform form-level validation, but today, almost every browser is perfectly capable of executing JavaScript code. I use JavaScript to validate dates as they are entered, to validate and reformat dollar figures and to enable or disable form controls based on selected options. This makes the user experience much better when working with data entry forms.

Try standardizing your validation functions to make them as portable as possible. For example, to create a generic date validation routine, pass the name of the control to the function as a parameter along with the error message you want to display (or you can just use a generic error message). Below is an example of what this function might look like.

 

jsvalidatedate

The RTrim() and isDate() functions are not standard JavaScript functions but rather functions that I have written, but you get the general idea. In the control's onChange event you call this function passing the name of the control, the error message you would like to display and the default value you would like to assign to the date control in the event that it is invalid. For example...

<input type="text" size="12" maxlength="10" name="txtDate" id="txtDate" onChange="return validateDate('txtDate', 'The date entered is not valid', '03/01/2008');">

Using JavaScript with your ASP applications can greatly enhance the user's experience. You can extend this technology to validate dollar amounts and reformat them for the user. While performing form validation using JavaScript is not nearly as simple as with ASP.NET, there's still no excuse for not introducing some level of control to your applications.

Use Include Files to Standardize Pages

In ASP.NET, developers have benefited tremendously from the introduction of Master pages. Master pages allow you to define one or more master, template pages that all pages in the application inherit from. When content is changed in the master page, all descendent pages reflect those changes.

This can be done to a lesser degree in classic ASP with include files. In my applications, I typically setup a standard banner at the top of the page that identifies the user logged in along with some standard links. I set this up in a separate ASP and include this below the opening <Body> tag in every page. For example...

<!-- #include file="pageHeading.asp" -->

In the "pageHeading.asp", make sure not to include any <HTML>, <HEAD> or <TITLE> tags since the sole purpose of this file is to be included in other pages that already contain these elements. Other than that, you can include any HTML you like and you can also reference external style sheets. You can also include ASP code that performs tasks such as looking up the user's name in a database or logging activity.

Although you may be saddled with the task of maintaining ASP applications, there's no reason you can't enhance these to improve the user experience and to make the management of the code simpler.

Friday, March 21, 2008 7:23:27 AM (Eastern Standard Time, UTC-05:00)  #    Comments [0]