Turn your ASP.NET pages into valid XHTML Strict pages

Many developers seem to find it difficult to get their ASP.NET pages rendering in a valid XHTML Strict fashion. The solution is just a quick MSDN lookup away. Only two steps are required.

One, declare the proper XHTML Strict DOCTYPE :

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
 "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

Two, edit your Web.Config file and the following to the System.Web section :

<xhtmlConformance mode="Strict"/>

ASP.NET will now adjust the HTML it outputs from controls and get rid of the infamous name attribute on the form tag.

Extending the SqlDataAdapter with a FillTimeout

The SqlDataAdapter has a CommandTimeout property but does offer any method to set any kind of timeout during the Fill method. If you are returning rather large data sets, you can quickly run into a problem. The obvious solution would be to inherit the SqlDataAdapter and simply override the Fill method, except that the SqlDataAdapter cannot be inherited. As a result, we must implement the same methods that the SqlDataAdapter does and attach them to a private internal SqlDataAdapter to do all the heavy lifting. With the use of anonymous delegates, we can easily rework the Fill methods to offer a new FillTimeout property and throw an exception when we exceed our desired timeout.

Continue reading “Extending the SqlDataAdapter with a FillTimeout”

Improved ASP JSON utility

Most of the projects that I have been working on lately did not require any advanced AJAX. Most of the time, stuffing the results of a simple GET into innerHTML has usually been sufficient. Recently, I needed to do some more advanced AJAX work so I started looking into JSON. There a hundreds of helper classes that people have dreamed up already for ASP.NET, however this project was under the Classic ASP (VBScript) umbrella.

I fell upon a nice little utility on aptly called aspjson. It is a nice utility except the implementation of multi-dimensional array support is flawed. Try to JSON an array that has dimensions with more than 10 elements and you will quickly see what I mean.

I rewrote the multi-dimensional array support from scratch and I am releasing the code under the same license as the original author as well as obviously attributing credit to Tuğrul Topuz for his original code.

Download the ASPJSON 2.1 source