The classic way for modifying page markup at runtime as we know it, is using ASP.NET Response Filter.
People have been using response filter for pulling off different tricks in SharePoint 2007 and it all worked fined until SharePoint 2010 arrived.
SharePoint 2010 uses ASP.NET substitution caching a.k.a Post Cache Substitution which allows it to cache the entire page except for certain portion of the page which continues to remain dynamic. More explanation can be found at http://blah.winsmarts.com/2006/05/26/aspnet-20–post-cache-substitution.aspx
Anyways so the thing is post cache substitution is not compatible with response filters. Here is the official Microsoft kb article http://support.microsoft.com/kb/2014472
The only solution they suggest is to either not use substitution caching or not use response filters. They are mutually exclusive. Well since we can’t change SharePoint the only option left is to not use response filter. So there isn’t really any solution right now. If you figure it out do leave out a comment on this post.

