This is a migrated thread and some comments may be shown as answers.

Large Viewstate and an optimized solution for it

8 Answers 293 Views
Let's talk about telerik (the good and the bad)
This is a migrated thread and some comments may be shown as answers.
Mostafa Anoosheh
Top achievements
Rank 1
Mostafa Anoosheh asked on 15 Jun 2006, 02:45 PM

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

8 Answers, 1 is accepted

Sort by
0
Ivelina Ganeva
Telerik team
answered on 16 Jun 2006, 08:13 AM

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
0
Mostafa Anoosheh
Top achievements
Rank 1
answered on 16 Jun 2006, 08:54 AM
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
0
Vassil Petev
Telerik team
answered on 16 Jun 2006, 09:58 AM
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
0
Mostafa Anoosheh
Top achievements
Rank 1
answered on 07 Aug 2006, 02:55 AM
Hello Ivy

Thanks for implement viewstate suggestion.

Best regards
Mostafa
0
Hanan
Top achievements
Rank 1
answered on 10 Nov 2006, 12:52 PM
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
0
Mostafa Anoosheh
Top achievements
Rank 1
answered on 11 Nov 2006, 08:51 AM
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
0
Hanan
Top achievements
Rank 1
answered on 11 Nov 2006, 11:11 AM
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
0
Mostafa Anoosheh
Top achievements
Rank 1
answered on 12 Nov 2006, 09:21 AM
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
Tags
Let's talk about telerik (the good and the bad)
Asked by
Mostafa Anoosheh
Top achievements
Rank 1
Answers by
Ivelina Ganeva
Telerik team
Mostafa Anoosheh
Top achievements
Rank 1
Vassil Petev
Telerik team
Hanan
Top achievements
Rank 1
Share this question
or