Quantcast

ASP.NET: HttpModule for Moving ViewState to Bottom

Get the WebProNews Newsletter:
[ Business]

There are two reasons why it is desirable to do so.

The first is for letting search engines see more of your content rather than the big portion of ViewState many sites have.

The other is perceived rendering time, which means that the content loads faster because it renders before the ViewState while the total rendering time remains the same.

That will decrease the load time of your website’s content.

Techniques to move the ViewState to the bottom of the WebForm has been published many times before.

What I wanted was adding the functionality to an HttpModule.

The technique to move the ViewState is borrowed from Scott Hanselman while the HttpModule implementation is my own.

As Scott writes, it is a very low impact technique (0.000995 second) even though it hasn’t been fully tested for a variety of scenarios.

The goal I’m trying to achieve is to build a reusable component that has 100% plug n play capabilities.

That’s where the HttpModule comes in.

You can just drop it into any existing website without changing any code.

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

Implementation

Download the ViewstateModule.cs below 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>

Download

ViewstateModule.zip (1,06 KB)

Tag:

Add to Del.icio.us | Digg | Reddit | Furl

Bookmark WebProNews:

Mads Kristensen currently works as a Senior Developer at Traceworks located
in Copenhagen, Denmark. Mads graduated from Copenhagen Technical Academy with a multimedia degree in
2003, but has been a professional developer since 2000. His main focus is on ASP.NET but is responsible for Winforms, Windows- and
web services in his daily work as well. A true .NET developer with great passion for the simple solution.

http://www.madskristensen.dk/

ASP.NET: HttpModule for Moving ViewState to Bottom
About Mads Kristensen
Mads Kristensen currently works as a Senior Developer at Traceworks located in Copenhagen, Denmark. Mads graduated from Copenhagen Technical Academy with a multimedia degree in 2003, but has been a professional developer since 2000. His main focus is on ASP.NET but is responsible for Winforms, Windows- and web services in his daily work as well. A true .NET developer with great passion for the simple solution.

http://www.madskristensen.dk/ WebProNews Writer
Top Rated White Papers and Resources
  • Darin See

    Beautiful, clean solution – thanks for posting.

  • http://www.dotnetdiary.com David Sugden

    Hi, I’ve come up with a slightly different solution that moves all ASP.NET hidden fields from the top of the form to the bottom and does not rely on string matching. I do this by intercepting the content written before the form children are rendered and then write it out after their rendering is complete.

    Unfortunately, it won’t work with your HttpModule but you might be interested anyway. Full details can be found at my blog.

    http://www.dotnetdiary.com/labels/Moving%20ViewState%20Field.html

  • http://www.just4wellness.com Heiko

    Hi Mads,

    I have looked for such a solution for a long time, for my wellness directory, based on asp.net.

    so, iI think to have big advantage in the results of any searchengines.

    best regards and thanks a lot.

    Heiko

  • http://quizilla.teennick.com/stories/19384010/ultimate-game-card Issac Maez

    What i don’t realize is actually how you are not actually much more neatly-favored than you may be now. You are very intelligent. You recognize therefore significantly on the subject of this topic, produced me for my part believe it from a lot of numerous angles. Its like women and men aren’t involved except it’s one thing to accomplish with Woman gaga! Your personal stuffs nice. All the time care for it up!