Did ASP.NET 2.0 SP1 Break Your Postbacks?

Are you using a whitespace filter maybe?

Several of the sites I work on have a white space filter implemented in them to remove white space in the html.  We do this for two reasons.  First, it makes the page smaller.  But, more importantly, it takes gaps out of images.  In some cases, we found using the white space filter was the only way to remove the gaps.  We also use it as a way of injecting code on the way back to the client… think of it as a global databinding technique.

Anyhow, once you remove all the white space, you end up with code that is all on one line.  This is great!  Exactly what we had in mind.  Except that well formed javascript has historically looked something link this:

<script lang=”javascript”>
<!–
// code goes here
// –>
</script>

So, we’ve needed to put some line feeds back in so that our javascript will run.  Otherwise, you end up with javascript code that will never run.  The appropriate search and replace strings to make this happen are:

newBuffer = Regex.Replace(newBuffer, “<!–”, “<!– \n” );
newBuffer = Regex.Replace(newBuffer, “// –>”, “// –> \n” );

However, once you upgrade your server to ASP.NET 3.5 or ASP.NET 2.0 Service Pack 1, this code no longer does the trick.  this is because Microsoft made all of their javascript XHTML compliant, adding CDATA sections around the code rather than comments.  To fix this you need to ADD the following two lines:

newBuffer = Regex.Replace(newBuffer, “//<!\\[CDATA\\[", "//<![CDATA[ \n");
newBuffer = Regex.Replace(newBuffer, "//\\]\\]>”, “//]]> \n”);

You need both sets because there may be other code that either you wrote, or third party vendors wrote that use the old format.

Related Post

Leave a Reply

Comment Policy:

  • You must verify your comment by responding to the automated email that is sent to your email address. Unverified comments will never show.Leave a good comment that adds to the conversation and I'll leave your link in.
  • Leave me pure spam and I'll delete it.
  • Leave a general comment and I'll remove the link but keep the comment.

Notify me of followup comments via e-mail

Bear