Login
Register
Tutorials
Forum
Career Development
Resources
Reviews
Jobs
Interview
Communities
Projects
Training
Silverlight Games
|
Bookmarks
|
New Members FAQ
|
Mentor
|
Code Converter
|
IT Companies
|
Peer Appraisal
|
Members
|
Revenue Sharing
|
Computer Jokes
|
New Posts
|
Social
|
Talk to Webmaster
Tony John
Facebook
Google+
Twitter
LinkedIn
Online Members
Santosh
Saranya
Padma
Minu
venkata raju
chandramohan
Ultimaterengan
Sunil Jas
More...
Join our online
Google+ community
for Bloggers, Content Writers and Webmasters
Resources
»
.NET programming
»
.NET Framework
Move ViewState to the bottom of the page.
Posted Date:
03-Feb-2005
Category:
.NET Framework
Author:
Dolph Larson
Member Level:
Bronze
Points
: 10
If you move your viewstate from the top of the page to the bottom, you will get better search engine spidering.
The following code sniplet will do the trick.
Example:
First:
I created an assembly called WebPageBase and a class in the assembly called PageBase. My class inherits from
System.Web.UI.Page like a normal aspx page does.
namespace WebPageBase
{
///
/// Main Base for RealtorNavigator Web
///
///[Designer(typeof(System.Web.UI.Page))]
public class PageBase :
System.Web.UI.Page
{
}
Next:
Add this method in the PageBase class:
///
/// This method overrides the Render() method for the page and moves the ViewState
/// from its default location at the top of the page to the bottom of the page. This
/// results in better search engine spidering.
///
///
protected override void Render( System.Web.UI.HtmlTextWriter writer )
{
// Obtain the HTML rendered by the instance.
StringWriter sw = new StringWriter();
HtmlTextWriter hw = new HtmlTextWriter( sw );
base.Render( hw );
string html = sw.ToString();
// Hose the writers we don't need anymore.
hw.Close();
sw.Close();
// Find the viewstate. Hope M$ doesn't decide to change the case of these tags anytime soon.
int start = html.IndexOf( @"<input type=""hidden""name=""__VIEWSTATE""" );
// If we find it, then move it.
if( start > -1 )
{
int end = html.IndexOf( "/>", start ) + 2;
// Strip out the viewstate.
string viewstate = html.Substring( start, end - start );
html = html.Remove( start, end - start );
// Find the end of the form and insert it there, since we can't put it any lower in the response stream.
int formend = html.IndexOf("") - 1;
html = html.Insert( formend, viewstate );
}
// Send the results back into the writer provided.
writer.Write( html );
}
Finally:
Inherit your aspx pages from the base class.
Example:
public class Default :
WebPageBase.PageBase
{
// Your code here
}
Note: I put my PageBase instead of the VisualStudio System.Web.UI.Page
Did you like this resource? Share it with your friends and show your love!
Tweet
Responses to "Move ViewState to the bottom of the page."
Author:
Mary Mathew
06 Feb 2005
Member Level:
Bronze
Points
: 0
That's a cool one, Dolph. We are looking forward to see more from you.....
Author:
Anil Rajan
21 Feb 2005
Member Level:
Gold
Points
: 0
kudos,
hey that's very good , the basic of aspx page is all end up being rendered as html ,using this concept a lot of user control manipulation is possible and you have thought another good things.
Feedbacks
Post Comment:
Notify me by email when others post comments to this article.
Do not include your name, "with regards" etc in the comment. Write detailed comment, relevant to the topic.
No HTML formatting and links to other web sites are allowed.
This is a strictly moderated site. Absolutely no spam allowed.
Name:
Sign In
to fill automatically.
Email:
(Will not be published, but
required
to validate comment)
Type the numbers and letters shown on the left.
Next Resource:
Inherited text control
Previous Resource:
Exploring Strongly Typed DataSet
Return to Resources
Post New Resource
Category:
.NET Framework
Post resources and
earn money
!
More Resources
Difference between 'ReadOnly' Field and 'Const'
Introduction On Text Compression Using Lempel, Ziv, Welch (LZW) method
Some Interview Questions.
List of Useful .NET Websites & others
Generic Login Control
Pagination
Popular Tags
Tag posting guidelines
Search Tags
(No tags found.)
Follow us on Twitter:
https://twitter.com/dotnetspider
Active Members
Today
Deepak Negi
(10)
venkata raju
(8)
Rakesh Chaubey
(6)
Last 7 Days
baskar
(295)
Ultimaterengan
(263)
Rakesh Chaubey
(184)
more...
Awards & Gifts
Email subscription
.NET Jobs
.NET Articles
.NET Forums
Articles Rss Feeds
Forum Rss Feeds
About Us
Contact Us
Copyright
Privacy Policy
Terms Of Use
Revenue Sharing sites
Advertise
Talk to
Tony John
Copyright © SpiderWorks Technologies Pvt Ltd., Kochi, India
2005 - 2012 All Rights Reserved.
.NET and other trademarks mentioned in this site belong to Microsoft and other respective trademark owners.
Articles, tutorials and all other content offered here is for educational purpose only.
We are not associated with Microsoft or its partners.