Friday, October 23, 2009

Okay, maybe this is no revelation for some of you out there, but here’s a quick, down-and-dirty way of displaying an HTML-Encoded column in a GridView. By default, the GridView will display bound columns with the HTML encoding so if you want to see the HTML formatting you need to do an HTMLDecode operation.

In the GridView.RowDataBound() event add the following line of code…

e.Row.Cells(4).Text = Server.HtmlDecode(e.Row.Cells(4).Text)

Substitute the number (in this case 4) with the column that contains the HTML, unless of course the column IS 4! You could also do an HTMLDecode on each column using the following syntax.

For Each oCell As TableCell in e.Row.Cells

oCell.Text = Server.HtmlDecode(oCell.Text)

Next

You are better off however if you simply decode the required columns because of performance. Not every column in your GridView is likely to contain HTML.

That’s all folks!!

 

Friday, October 23, 2009 10:44:29 AM (Eastern Standard Time, UTC-05:00)  #    Comments [0]
 Saturday, January 24, 2009
This article outlines methods to successfully connect to SQL server through the Windows Firewall.
Saturday, January 24, 2009 6:40:08 PM (Eastern Standard Time, UTC-05:00)  #    Comments [0]
 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]
 Monday, February 11, 2008
A comparison of the benefits of Web Applications over traditional Windows applications.
Monday, February 11, 2008 8:42:46 AM (Eastern Standard Time, UTC-05:00)  #    Comments [0]
 Saturday, February 09, 2008
A new template-based code generator for VB.NET, C#.NET, JavaScript and SQL Server coding.
Saturday, February 09, 2008 12:17:54 PM (Eastern Standard Time, UTC-05:00)  #    Comments [0]