Steve Smith's Blog

Musings on Software and the Developer Community

SEO Tip Move Hidden ASPNET Fields To Bottom of Page

Here’s a quick SEO tip from Teemu (via email) that I’ve been meaning to mention – there’s a new feature in .NET 3.5 SP1 that lets you control where hidden form fields are rendered by ASP.NET.  To set it, go into web.config and add the following:

<pages renderAllHiddenFieldsAtTopOfForm="false" />

The default for this is true (which is how it’s always behaved since 1.0).  You can read more about it on MSDN.

What’s the point?

There are pros and cons to which way you go with this setting.  The default setting ensures that the data in hidden form fields like __VIEWSTATE is available early in the browser-side page loading cycle, so that if a user clicks a button and posts back the page before it has fully rendered/loaded, the server will still get the contents of these hidden fields.  This is a good thing, as otherwise the server will likely be unable to process the page.

On the other hand, there’s a good argument to be made that search engines tend to weight content higher based on how close to the top of the page it is, and that in some cases search engine bots may only grab a relatively small chunk of a page (from the top) as part of their indexing process.  Assuming there is some truth to this, then pushing real page content as high up in the actual HTML as possible would tend to yield better placements in search engines.  Thus, setting this so that hidden fields render at the bottom of the page could make a big difference in how close the page’s real content is to the top of the HTML file, especially if there is a great deal of viewstate on the page.

YMMV

Your Mileage May Vary.  The best way to determine whether or not this setting is of any use to you is to try it out.  It’s really only appropriate for public-facing pages, and most of those shouldn’t be using ViewState or posting back in any event if they’re meant to be indexed by search engines.  That said, if they’re not posting back, they really should have ViewState disabled and/or pushed to the bottom of the page since there’s really now down side to doing so.

    kick it on DotNetKicks.com

Friday, 05 December 2008

Comments

 avatar

simone said on 08 Dec 2008 at 7:08 AM

Unfortunately it's notmoving down

<input type="hidden" name="__EVENTTARGET" id="__EVENTTARGET" value="" />

<input type="hidden" name="__EVENTARGUMENT" id="__EVENTARGUMENT" value="" />

<input type="hidden" name="__VIEWSTATE" id="__VIEWSTATE" value="" />

but only

<input type="hidden" name="__SCROLLPOSITIONX" id="__SCROLLPOSITIONX" value="0" />

<input type="hidden" name="__SCROLLPOSITIONY" id="__SCROLLPOSITIONY" value="0" />

Sometimes microsoft has the real power to upset me... :)


 avatar

smnbss said on 08 Dec 2008 at 7:14 AM

This happen because __VIEWSTATE is rendered inside

Page.BeginFormRender(HtmlTextWriter writer, string formUniqueID)

using the method

this.RenderViewStateFields(writer);

While __SCROLLPOSITIONX/Y are added to the form using

this.ClientScript.RegisterHiddenField("__SCROLLPOSITIONX", this._scrollPositionX.ToString(CultureInfo.InvariantCulture));

this.ClientScript.RegisterHiddenField("__SCROLLPOSITIONY", this._scrollPositionY.ToString(CultureInfo.InvariantCulture));

on the same funcion, so the 2 hidden fields behave in a different way


 avatar

Yoann. B said on 26 Dec 2008 at 5:50 AM

Hi,

Great work. I also wrote an article about that :

Moving ViewState Hidden Input to Page Bottom : blog.sb2.fr/.../Moving-ViewStat

Moving Event Validation Hidden Input to Page Bottom : blog.sb2.fr/.../Moving-ViewStat

Hope this help's.


 avatar

Abilawa said on 01 Sep 2009 at 5:43 PM

Thanks for this nice info, it's so useful for me.


 avatar

Jones said on 18 Oct 2009 at 4:09 AM

When i try to add this to my web config i get an iis error which doen't diplay any pages my local test is iis 7.0. Asp.net 3.5 sp1


 avatar

kerja keras said on 03 Dec 2009 at 12:49 PM

Thanks for taking the time to discuss this, I feel strongly about it and love learning more on this topic. If possible, as you gain expertise, would you mind updating your blog with more information? It is extremely helpful and beneficial to your readers.