Did ASP.NET 2.0 SP1 Break Your Postbacks?

Tagged with:

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.

If you're new here, you may want to subscribe to my RSS feed. Thanks for visiting!

Related Post

Tagged with:
kick it on DotNetKicks.com

Leave a Reply