Move ViewState to the page bottom

In this example we will move the ViewState from the top of the page to the bottom. This is believed to help search engines read the move important content of the page, rather that have to deal with all the encoded information.

What you do is override the Render method

        protected override void Render(HtmlTextWriter writer)
            StringWriter stringWriter = new StringWriter();
            using (HtmlTextWriter htmlWriter = new HtmlTextWriter(stringWriter))
                string html = stringWriter.ToString();
                string updatedHtml;

                int start = html.IndexOf("< input type=\"hidden\" name=\"__VIEWSTATE\"");

                if ((start >= 0))
                    int end = (html.IndexOf("/ >", start) + 2);
                    string viewStateInput = html.Substring(start, (end - start));

                    updatedHtml = html.Remove(start, (end - start));
                    int formEndStart = (updatedHtml.IndexOf("< /form>"));
                    if ((formEndStart >= 0))
                        html = updatedHtml.Insert(formEndStart, viewStateInput);


No comments yet.

Add Yours

  • Author Avatar


Comment Arrow

About Author


Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning hands down.