DHTML Behaviors and THEAD-TBODY-TFOOT Tags

Published 30 November 04 09:49 AM | despos

In the January 2004 issue of MSDN Magazine, I demonstrated how to create a DataGrid control with draggable columns and client-side sorting. In doing so, I modified a free DHTML behavior that Dave Massy wrote as the companion code of an old DHTML Dude column for MSDN online.

According to the MSDN Magazine rating system, that article got rave reviews and received excellent feedback. About 12 months later, I can say that readers raised a couple of major issues about the code:

  • 1) The DHTML behavior deployed as a separate (and scattered) HTC file
  • 2) The necessity of modifying the DataGrid control to make it output extra table tags like THEAD, TBODY, TFOOT.

In the end, using my closing sentences,

A symbiotic relationship between the DataGrid and DHTML can be attained and has lots of advantages for users. But as you can see, it takes a bit of work to coerce the DataGrid into doing everything you want it to do. 

Following up to that, a few days ago I took a reader's suggestion about building a DataGrid that allows to move rows up and down on the client and post changes to the server. Once again, I've found a free DHTML behavior to adapt. This time, it is rowover.htc and belongs to the MSDN DHTML Behavior Library. As mentioned, the results will appear in the March 2005 issue of MSDN Magazine.

How did I work around the two aforementioned issues? Let's start with #2.

In ASP.NET 1.1, the Table control only outputs the <table> tag. Similarly, TableRow only manages <tr> tags. If you install a post 1.1 patch for accessibility, TableCell can sometimes morph into <th>. That's all, though. It doesn’t mean you can’t build a fully qualified table, however. You can always make a control output plain text like Write("<thead>").

In ASP.NET 2.0, the Table and related controls have been fixed. So the TableRow class has a property TableSection that indicates where the row belongs to, be it TBODY, THEAD or TFOOT. And the markup is generated accordingly.

row.TableSection = TableRowSection.TableHeader;

As far as Beta 1 is concerned, though, this doesn’t work automatically for grid controls like DataGrid and GridView. The good news is that unlike ASP.NET 1.1 you now have a more effective workaround to apply. In ASP.NET 1.1, the only reliable trick I've been able to find (and readers' post-article suggestions didn't help much) is to output the grid's content to a string and parse to insert missing tags. By moving this code to an output filter, you can perhaps apply changes to all grids automatically, but I don't see significant performance advantages. Some readers suggested to override RenderBeginTag or similar methods. Believe me, no way. The DataGrid delegates to the inner child table control any rendering tasks. And the Table control doesn't support extra tags. Either you replace the whole rendering engine of the DataGrid (challenging, but really worthwhile?) or you do it the way I did.

What's new in ASP.NET 2.0? Because the new TableRow control has a TableSection property you can now successfully override the CreateRow method on a GridView and the CreateItem method on a old-fashioned DataGrid control.

protected override GridViewRow CreateRow(
   int rowIndex,
   int dataSourceIndex,
   DataControlRowType rowType,
   DataControlRowState rowState)
{
   GridViewRow row;
   row = new GridViewRow(rowIndex, dataSourceIndex, rowType, rowState);

   switch (rowType) {
      case DataControlRowType.Header:
          row.TableSection = TableRowSection.TableHeader;
          return row;
        :
   }
}
Neat and elegant, isn't it?

What about #1? To avoid sparse files like HTC files, in ASP.NET 1.1 you can write a custom HTTP handler that retrieves and downloads the resource setting the proper MIME type. Using a HTTP handler requires you to enter a new line to the web.config file and likely a new entry to the IIS metabase if you decide to use a custom extension (not strictly required).

In ASP.NET 2.0, a new system HTTP handler (named WebResource.axd)  and the [WebResource] attribute let you retrieve resources from assemblies. WebResource is an assembly-level attribute through which you to mark embedded resources as URL-accessible. You first add the HTC file to the project as an embedded resource and then insert the following code to the AssemblyInfo file of the project:


[assembly: WebResource("Mover.htc", "text/javascript")]

To programmatically access the resource (i.e., to compile the Style property of the control to bind the behavior) you use a new method on the Page class—the GetWebResourceUrl method.

I'll probably cover WebResource in a future post; in the mean time, you can take a look at what one of its authors has to say about it. Handing over to Nikhil. And once again.

Comments

# TrackBack said on November 30, 2004 05:04 AM:

I know, I haven't written as much recently.

# Kevin Daly said on November 30, 2004 11:36 AM:

I'm *really* looking forward to WebResource: I think it will be a great blessing for people writing custom controls. If you've faced the ickiness of embedding Javascript in server code, which I assume you have, you'll know what I mean.
The situation we have at the moment is that most of us rightly want to avoid deploying separate script files along with out controls, but constructing script as a string within the control itself is horrible (and it's even more horrible to edit afterwards).
ASP.NET 2 can't come soon enough :-) (Please God let them not drop any more features between now and the release!).

# DinoE said on November 30, 2004 11:57 AM:

Totally agree!
However, in ASP.NET 1.1 you can resort to some tricks (OK--tricks so nothing compared to WebResource) to alleviate the issue.

1) Embed a Javascript file as a resource into the project and load and bind it programmatically. Easier than building a string dynamically but still a pain in the neck because of the browser caching
2) Use a JavascriptWriter class to reduce the workload (and bother)
3) Write your own HTTP handler and use it in much the same way they do in 2.0

Sure, this has still nothing to do with the [WebResource] attribute, but it's (much) better than nothing.

This said, ASP.NET 2.0 can't come soon enough!

# Alex Thissen said on December 5, 2004 05:59 PM:

For those of you interested, I already wrote the WebResourceHandler for ASP.NET 1.1 some time ago. You can download the source here:
http://www.alexthissen.nl/weblog/PermaLink.aspx?Guid=f0e2f701-1b0d-48ca-960e-68bbbf13e467

# sonnerie polyphonique said on December 14, 2004 07:15 AM:

verry good

# Gdsffsd said on May 25, 2007 08:24 AM:

<a href="extremedrawing.tripod.com/">adult comics</a>

# Britney said on June 16, 2007 03:51 PM:

You have a nice site.

replicawatchesdiscount.info/replica-watcheslook-up-antique-ladies-rolex-watch.php">replicawatchesdiscount.info/.../look-up-antique-ladies-rolex-watch.php

replicawatchesdiscount.info/replica-watchesessential-watches-rolex.php">replicawatchesdiscount.info/.../essential-watches-rolex.php

replicawatchesdiscount.info/replica-watchesimmitation-rolex-watches.php">replicawatchesdiscount.info/.../immitation-rolex-watches.php

replicawatchesdiscount.info/replica-watchesjared-jewlers-rolex-watch.php">replicawatchesdiscount.info/.../jared-jewlers-rolex-watch.php

<a href="replicawatchesdiscount.info/replica-watchescartier-replica-watches.php">cartier">replicawatchesdiscount.info/.../cartier-replica-watches.php">cartier replica watches</a>

<a href="replicawatchesdiscount.info/replica-watchesrolex-date-watches.php">rolex">replicawatchesdiscount.info/.../rolex-date-watches.php">rolex date watches</a>

<a href="replicawatchesdiscount.info/replica-watchesswiss-replica-rolex-watches.php">swiss">replicawatchesdiscount.info/.../swiss-replica-rolex-watches.php">swiss replica rolex watches</a>

replicawatchesdiscount.info/replica-watchesbvlgari-replica-watches.php">replicawatchesdiscount.info/.../bvlgari-replica-watches.php

<a href="replicawatchesdiscount.info/replica-watchesmasterpiece-replica-rolex.php">masterpiece">replicawatchesdiscount.info/.../masterpiece-replica-rolex.php">masterpiece replica rolex</a>

<a href="replicawatchesdiscount.info/replica-watchescertified-preowned-rolex-watches.php">certified">replicawatchesdiscount.info/.../certified-preowned-rolex-watches.php">certified preowned rolex watches</a>

replicawatchesdiscount.info/replica-watchesreplica-mens-watches.php">replicawatchesdiscount.info/.../replica-mens-watches.php

replicawatchesdiscount.info/replica-watchesreplica-jacob-watch.php">replicawatchesdiscount.info/.../replica-jacob-watch.php

<a href="replicawatchesdiscount.info/replica-watches$80-fake-rolex-watches.php">$80 fake rolex watches</a>

<a href="replicawatchesdiscount.info/replica-watchesfake-rolexes.php">fake rolexes</a>

replicawatchesdiscount.info/replica-watcheshublot-replica-watches.php

# www.IcedOutPlanet.tk said on January 18, 2008 05:12 PM:

www.IcedOutPlanet.tk

Best Jacob Watch replicas!

Check out WWW.ICEDOUTPLANET.TK

WWW.ICEDOUTPLANET.TK

Leave a Comment

(required) 
(required) 
(optional)
(required)