Best Practices
General > Best Practices > Moving the ViewState to the bottom of the page View modes: 
User avatar
Member
Member
jeremy - 5/9/2008 12:08:31 PM
   
Moving the ViewState to the bottom of the page
I am working on building out my first site to Kentico. Everything is going great so far. I used the technique outlined on the following site to move the ViewState to the bottom of the page using an HttpModule.

http://blog.madskristensen.dk/post/An-HttpModule-that-moves-ViewState-to-the-bottom.aspx

I had to edit the code slightly because I was getting an error on some of the CMS Desk pages. I basically just made the following modifications.

Changed:
int formEndStart = html.IndexOf("</form>") - 1;

To be:
int formEndStart = html.IndexOf("</form>");

So far everything seems to be working fine, but I am wondering if anyone else has tried this technique with Kentico, and if anyone can foresee any problems it may create.

User avatar
Member
Member
Mufasa - 5/12/2008 10:53:48 AM
   
RE:Moving the ViewState to the bottom of the page
That's a good idea. But it has some issues. It isn't robust enough in some situations. I use the method from http://blogs.msdn.com/tom/archive/2008/03/14/validation-of-viewstate-mac-failed-error.aspx to fix a few other things. It is also more robust for when the ViewState is split among multiple input values (when the ViewState gets too long some browsers choke on it, so ASP.NET has a built-in feature to split the chunk up).

Then I add ViewState compression from http://www.codeproject.com/KB/viewstate/ViewStateCompression.aspx.

But, this is simpler code when written as Page overrides instead of an HTTP handler. A handler is easier to add for a non-coder or for sites that don't lend well to global <pages> overrides. Some sites, like Kentico, are so complicated that I haven't tried doing all this on them because it can sometimes mess things up and I dont' have a test site setup to play with just yet. So, I haven't tried these on my Kentico sites yet, but it'll be a project for a rainy day...

User avatar
Member
Member
jeremy - 5/12/2008 11:08:58 AM
   
RE:Moving the ViewState to the bottom of the page
Thanks for the info, Mufasa. I actually did run into some problems with some of the pages in the Site Manager section so I went ahead and removed the HTTP Handler I was using. I will take a look at the links you provided and see if I can get it to work using that method.