utorok, 14. augusta 2007

ASP.NET - DataGrid rendered with thead, tbody, th, ....

By default DataGrid is rendered with tags <table>, <tr> and <td>. To make styling with CSS easier it would also suitable to render also tags <thead>, <tbody>, <th> etc. To solve this problem I created custom DataGrid derived from System.Web.UI.WebControls.DataGrid, where in overriden method OnPreRender are realized modifications:


   1:  using System;

   2:  using System.Reflection;

   3:  using System.Web.UI;

   4:  using System.Web.UI.WebControls;

   5:   

   6:  namespace NMarian.Controls

   7:  {

   8:      public class DataGrid : System.Web.UI.WebControls.DataGrid

   9:      {

  10:          protected override void OnPreRender(EventArgs e)

  11:          {

  12:              Table table = Controls[0] as Table;

  13:   

  14:              if (table != null && table.Rows.Count > 0)

  15:              {

  16:                  table.Rows[0].TableSection = TableRowSection.TableHeader;

  17:                  table.Rows[table.Rows.Count - 1].TableSection = TableRowSection.TableFooter;

  18:   

  19:                  FieldInfo field = typeof(WebControl).GetField("tagKey", BindingFlags.Instance | BindingFlags.NonPublic);

  20:   

  21:                  foreach (TableCell cell in table.Rows[0].Cells)

  22:                  {

  23:                      field.SetValue(cell, HtmlTextWriterTag.Th);

  24:                  }

  25:              }

  26:   

  27:              base.OnPreRender(e);

  28:          }

  29:      }

  30:  }

nedeľa, 12. augusta 2007

ASP.NET AJAX - Script compression doesn't work in IE6

I try to enable compression in script resource handler in web.config file:


   1:  <system.web.extensions>

   2:      <scripting>

   3:          <scriptResourceHandler enableCompression="true" enableCaching="true" />

   4:      </scripting>

   5:  </system.web.extensions>


Analyzing the network traffic I discover that this works fine under Opera, Mozilla Firefox, IE7 but doesn't work under IE6. Response headers for Mozilla Firefox:

HTTP/1.1 200 OK
Content-Length: 23423
Expires: Mon, 11 Aug 2008 11:35:45 GMT
Date: Sun, 12 Aug 2007 11:35:45 GMT
Content-Type: application/x-javascript
Server: Microsoft-IIS/6.0
X-Powered-By: ASP.NET
X-AspNet-Version: 2.0.50727
Content-Encoding: gzip
Cache-Control: public
Last-Modified: Sat, 04 Aug 2007 12:23:19 GMT

Response headers for IE6:

HTTP/1.1 200 OK
Content-Length: 84019
Expires: Mon, 11 Aug 2008 11:44:23 GMT
Date: Sun, 12 Aug 2007 11:44:23 GMT
Content-Type: application/x-javascript
Server: Microsoft-IIS/6.0
X-Powered-By: ASP.NET
X-AspNet-Version: 2.0.50727
Cache-Control: public
Last-Modified: Sat, 04 Aug 2007 12:23:19 GMT

Can anybody explain this behavior of ASP.NET AJAX?