Workaround for Bug in ASP.NET Version 1.1

Changes in ASP.NET version 1.1 can generate a postback script with a bug in it.  It is particularly a problem for anyone using many of the page template solutions.  I posted both C# and VB workarounds on the ASP.NET forums, and here's the C# code:

using System.IO;
using System.Text;

protected override void Render(HtmlTextWriter writer) {
  StringBuilder stringBuilder = new StringBuilder();
  StringWriter stringWriter = new StringWriter(stringBuilder);
  HtmlTextWriter htmlWriter = new HtmlTextWriter(stringWriter);
  base.Render(htmlWriter);
  string html = stringBuilder.ToString();

  int start = html.IndexOf("<form name=\"") + 12;
  int end = html.IndexOf("\"", start);
  string formID = html.Substring(start, end - start);
  string replace = formID.Replace(":", "_");
  html = html.Replace("document." + formID, "document." + replace);
  writer.Write(html);
}

Note:  This is a bug in the official release of 1.1, and it was tested with it too.  I'm not referring to a beta.

Update:  Quickfix now available as of 4/29/2003.

No Comments