SEO ASP.NET - Move Keywords Up By Moving ViewState Down

9. September 2009 13:13 by Dan in SEO  //  Tags: , ,   //   Comments (0)

One aspect of on page SEO is to get your keywords to the top of the page.  Now if you're not using nice clean ASP.NET MVC, which by the way doesn't have a nasty viewstate, but the traditional aspx code behind model then as you probably know you the more controls that use viewstate the larger the hidden input field containing the actual viewstate data will be. 

The viewstate also increases page size which is another separate issue but what I wanted to do was look at moving my keywords towards the top of the page whilst keeping viewstate.

There are a few ways of getting around this problem like keeping viewstate on the server (which I might look at later) but the option I went for is to just move the hidden viewstate to the bottom of the form.

I can't take the credit for this fix as I found the solution here http://forums.seochat.com/search-engine-optimization-28/how-can-i-move-the-viewstate-hidden-field-in-asp-6038.html so thought I'd just redistribute.

I had to change the code slightly but here's my base page using the render method to change location of the viewstate:

   1: public class BasePage : Page
   2: {
   3:     protected override void Render(HtmlTextWriter writer)
   4:     {
   5:         var stringWriter = new System.IO.StringWriter(); 
   6:         var htmlWriter = new HtmlTextWriter(stringWriter); 
   7:         base.Render(htmlWriter); 
   8:  
   9:         string html = stringWriter.ToString(); 
  10:         int StartPoint = html.IndexOf("<input type=\"hidden\" name=\"__VIEWSTATE\""); 
  11:         if (StartPoint >= 0) { 
  12:         int EndPoint = html.IndexOf("/>", StartPoint) + 2; 
  13:         string viewstateInput = html.Substring(StartPoint, EndPoint - StartPoint); 
  14:         html = html.Remove(StartPoint, EndPoint - StartPoint); 
  15:         int FormEndStart = html.IndexOf("</form>") - 1; 
  16:         
  17:             if (FormEndStart >= 0) { 
  18:             html = html.Insert(FormEndStart, viewstateInput); 
  19:         } 
  20:         } 
  21:         writer.Write(html); 
  22:     }
  23:  
  24: }

Pingbacks and trackbacks (1)+

Add comment

  Country flag

biuquote
  • Comment
  • Preview
Loading