Moving ViewState to the Bottom of the Page

Home Forums Web Development ASP.Net Moving ViewState to the Bottom of the Page

This topic contains 0 replies, has 2 voices, and was last updated by  Nitesh 6 years, 11 months ago.

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
  • #3430



    I was working on a ASP.NET seo friendly website and therefore to move the ASP.NET page ViewState to the bottom of the page in order to get Google to pay more attention to my page and less to the wad of ViewState.
    Help me



    Hello Nitesh,
    When we go through page life cycle Render events responsible for display the controls on browser. This event convert server side control into html control.This is event is also part of saving view state on page.
    if you want to deep knowledge of page life cycle then go through the author code url:

    Below is the code of render event that move the ViewState to the bottom of page.

     protected override void Render(System.Web.UI.HtmlTextWriter writer)
            System.IO.StringWriter stringWriter = new System.IO.StringWriter();
            HtmlTextWriter htmlWriter = new HtmlTextWriter(stringWriter);
            string html = stringWriter.ToString();
            int StartPoint = html.IndexOf(" < input type=\"hidden\" name=\"__VIEWSTATE\"");
            if (StartPoint >= 0)
                int EndPoint = html.IndexOf("/>", StartPoint) + 2;
                string viewstateInput = html.Substring(StartPoint, EndPoint - StartPoint);
                html = html.Remove(StartPoint, EndPoint - StartPoint);
                int FormEndStart = html.IndexOf("") - 1;
                if (FormEndStart >= 0)
                    html = html.Insert(FormEndStart, viewstateInput);


    Thanx Alot pawan for the help

Viewing 3 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic.