An HttpModule That Moves ViewState to the Bottom

There are two reasons why it is desirable todo so. The first is for letting search engines see more of your contentrather than the big portion of ViewState many sites have. The other isperceived rendering time, which means that the content loads fasterbecause it renders before the ViewState while the total rendering timeremains the same. That will decrease the load time of your website.scontent.

Techniques to move the ViewState to the bottomof the WebForm has been published many times before. What I wanted wasadding the functionality to an HttpModule. The technique to move theViewState is borrowed from Scott Hanselman while the HttpModuleimplementation is my own. As Scott writes, it is a very low impacttechnique (0.000995 second) even though it hasn.t been fully tested fora variety of scenarios.

The goal I.m trying to achieve is to build areusable component that has 100% plug .n play capabilities. That.swhere the HttpModule comes in. You can just drop it into any existingwebsite without changing any code.

I see no reasons why not to move the ViewStateto the bottom, which makes me believe that Microsoft should have donethat by default in the first place.

Implementation

Download ViewstateModule.cs and put in the App_Code folder of your website. Then add these lines to the web.config and you.re ready to go.

<httpModules>
<add type="ViewstateModule" name="ViewstateModule" />
</httpModules>

Twitter Digg Delicious Stumbleupon Technorati Facebook Email

No comments yet... Be the first to leave a reply!