Moving ViewState to the Bottom of the Page

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

    Hello

    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

    #3432
    Pavan
    Member

    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:

    http://www.authorcode.com/asp-net-page-life-cycle/

    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);
            base.Render(htmlWriter);
            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);
                }
            }
            writer.Write(html);
    
        }
    
    
    
    
    #3433
    Nitesh
    Member

    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.