Saturday, May 17, 2008

Immediacy <head> gotcha

I'm currently doing some Immediacy customisation work using templates developed by an Immediacy partner.

I was getting a very strange effect on one particular page when hitting a search button that did a form post... basically the CSS got lost.

I checked the templates thoroughly and couldn't see the problem but when comparing the page before and after a post I noticed that the lines in the head tag had mysteriously had their "href" attributes changed. It appears that something within the Immediacy page pipeline attempts to "play" with the contents of the head tag and on postback it makes a right mess.

I'm guessing it's to do with the themes support within Immediacy as even on a standard page there are a bunch of injected <link> elements picking up CSS from a handler and what it appeared to be doing on postback was moving the href attributes from elements in the template to the next sibling - I even ended up with <meta> tags with a href's pointing to CSS files!

The solution to the issue is to ensure that the head tag, which normally reads as:

<head runat="server">

Is attributed without viewstate and therefore reloaded from the original ASCX file each time.

<head runat="server" enableviewstate="false">

This has now solved the issue, and on further investigation I found that more than just this one page was being affected but due to the CSS in the template it wasn't quite so obvious. I've simply done a search and replace on all templates in the solution and replaced the head tag as above - problem solved.

No comments: