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.
/// Summary description for OptimizedBasePage
public class OptimizedBasePage : Page
protected override void Render(HtmlTextWriter writer)
StringWriter stringWriter = new StringWriter();
HtmlTextWriter htmlWriter = new HtmlTextWriter(stringWriter);
string html = stringWriter.ToString();
//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);
8 Answers, 1 is accepted
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.
the telerik team
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
the telerik team
Thanks for implement viewstate suggestion.
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.
you can make class like this:
|/// Summary description for OptimizedBasePage|
|public partial class OptimizedBasePage : Page|
|protected override void Render(HtmlTextWriter writer)|
|StringWriter stringWriter = new StringWriter();|
|HtmlTextWriter htmlWriter = new HtmlTextWriter(stringWriter);|
|string html = stringWriter.ToString();|
|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);|
and use it.
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?
I don't work with DNN. but i think DNN use same approch.
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.