Large Viewstate and an optimized solution for it

9 posts, 0 answers
  1. Mostafa Anoosheh
    Mostafa Anoosheh avatar
    462 posts
    Member since:
    Nov 2005

    Posted 15 Jun 2006 Link to this post

    Hello,
    In some pages of Telerik site we can see large viewstate.
    you can simply send viewstate to end of pages for faster download & better indexing in search engines.

    My suggestion based on 2 posts from scott
    1. Google AdSense and ASP.NET View State
    2. Using a Base Class to Fiddle with a Page's Rendered Output
    you can use this base class that the ASP.NET pages in your application extend for optimizing output of pages in your site.

    using System.IO;
    using System.Web.UI;

    /// <summary>
    /// Summary description for OptimizedBasePage
    /// </summary>
    public class OptimizedBasePage : Page
    {
     protected override void Render(HtmlTextWriter writer)
     {
      StringWriter stringWriter = new StringWriter();
      HtmlTextWriter htmlWriter = new HtmlTextWriter(stringWriter);
      base.Render(htmlWriter);
      
      string html = stringWriter.ToString();
      int StartPoint;
      int SLength;  
      //remove some invisible characters to compress output
      html = html.Replace("\t", "");// tabs
      html = html.Replace("  ", " ");// double spaces
      html = html.Replace(" />", "/>");// space before end of tags
      StartPoint = html.IndexOf("<input type=\"hidden\" name=\"__VIEWSTATE\"");
      if (StartPoint >= 0)
       // does __VIEWSTATE exist?
      {
       SLength = html.IndexOf("/>", StartPoint) + 2 - StartPoint;
       string ViewStateInput = html.Substring(StartPoint, SLength);
       html = html.Remove(StartPoint, SLength);
       int FormEndStart = html.IndexOf("</form>");
       html = html.Insert(FormEndStart, ViewStateInput);
      }
      writer.Write(html);
     }
    }

    Best regards
    Mostafa

  2. Ivelina Ganeva
    Admin
    Ivelina Ganeva avatar
    2 posts

    Posted 16 Jun 2006 Link to this post


    Hi Mostafa,

    Thank you for your suggestion.
    We're currently working on the optimization of telerik.com which includes optimization of T-SQL queries, cache, fast output of pages.

    Best wishes,
    Ivy
    the telerik team
  3. Mostafa Anoosheh
    Mostafa Anoosheh avatar
    462 posts
    Member since:
    Nov 2005

    Posted 16 Jun 2006 Link to this post

    Hello Ivy,
    Thanks for reply & good news.
    I want to reffer you to another link that make better performance for paging.
    A More Efficient Method for Paging Through Large Result Sets 


    Best regards
    Mostafa
  4. Vassil Petev
    Admin
    Vassil Petev avatar
    1765 posts

    Posted 16 Jun 2006 Link to this post

    Thanks again, Mostafa, for your dedication to help us. We will review the links provided. Please, let us know if you feel our site needs improvements in the future - we are open to all suggestions.


    Best wishes,

    Ivy
    the telerik team
  5. Mostafa Anoosheh
    Mostafa Anoosheh avatar
    462 posts
    Member since:
    Nov 2005

    Posted 06 Aug 2006 Link to this post

    Hello Ivy

    Thanks for implement viewstate suggestion.

    Best regards
    Mostafa
  6. Hanan
    Hanan avatar
    2 posts
    Member since:
    Nov 2006

    Posted 10 Nov 2006 Link to this post

    Hi Mostafa
    I would like to implement the base class code you've suggested into my website (Built upon DNN) but I am afraid that I will crash some functionalities, specially that it is not me the main developer who developed the site, so I am afraid to ruin something by removing the ViewState hidden field value.
    Please advise me.
    Thanks
    Hanan
  7. Mostafa Anoosheh
    Mostafa Anoosheh avatar
    462 posts
    Member since:
    Nov 2005

    Posted 11 Nov 2006 Link to this post

    Hello Hanan,
    you can make class like this:
    using System.IO;  
    using System.Web.UI;  
     
    /// <summary> 
    /// Summary description for OptimizedBasePage  
    /// </summary> 
    public partial class OptimizedBasePage : Page  
    {  
        protected override void Render(HtmlTextWriter writer)  
        {  
            StringWriter stringWriter = new StringWriter();  
            HtmlTextWriter htmlWriter = new HtmlTextWriter(stringWriter);  
            base.Render(htmlWriter);  
              
            string html = stringWriter.ToString();  
            int StartPoint;  
            int SLength;  
            string ViewStateInput = "";  
            StartPoint = html.IndexOf("<input type=\"hidden\" name=\"__VIEWSTATE\"");  
            if (StartPoint >= 0)  
                // does __VIEWSTATE exist?  
            {  
                SLength = html.IndexOf("/>", StartPoint) + 2 - StartPoint;  
                ViewStateInput = html.Substring(StartPoint, SLength);  
                htmlhtml = html.Remove(StartPoint, SLength);  
                int FormEndStart = html.IndexOf("</form>");  
                htmlhtml = html.Insert(FormEndStart, ViewStateInput);  
            }  
              
            writer.Write(html);  
        }  

    and use it.

    Best regards
  8. Hanan
    Hanan avatar
    2 posts
    Member since:
    Nov 2006

    Posted 11 Nov 2006 Link to this post

    Mostafa
    But you didn't asnwer my main question. Will removing the ViewState ruin any functionality that I don't know?
    Also another question, isn't it affecting the performance to do this removing process before rendering the page?

    Please advise.
    Thanks
    Hanan
  9. Mostafa Anoosheh
    Mostafa Anoosheh avatar
    462 posts
    Member since:
    Nov 2005

    Posted 12 Nov 2006 Link to this post

    Hello Hanan,
    I don't work with DNN. but i think DNN use same approch.
    About performance:
    We have a site with about 200,000 users and average 1100 online users and we use this solution to make better client rendering for pages but performance related to your server.

    Best regards
    Mostafa
Back to Top