Tim

Footprints in the snow of a warped mind

Quick ASP.Net tip: Half your page size in ASP.Net instantly

Where to find me

Flickr Icon  Twitter Icon  Linked In Icon  FaceBook Icon  Windows Live Alerts Butterfly  RSS 2.0 

Tag Cloud

AJAX (4) ASP (6) ASP.Net (52) Error Reporting (4) Web Service (2) WSDL (1) Atlas (2) Business (76) Business Start-up Advice (25) Client (14) Expanding Your Business (17) C# (17) Canoeing (4) Canoe Racing (5) Cheshire Ring Race (5) Racing (2) Training (4) CIMA (1) Cisco (1) 7970G (1) CSS (3) dasBlog (4) DDD (1) Design (9) Icons (1) Development (13) eCommerce (1) General (39) Christmas (6) Fun and Games (11) Internet (22) Random (46) RX-8 (8) Home Cinema (2) Hosting (2) IIS (10) iPhone (1) JavaScript (4) jQuery (1) Marketing (5) Email (1) Multipack (1) Networking (2) Nintendo (1) OS Commerce (1) Photography (1) PHP (1) PowerShell (2) Press Release (1) Productivity (2) Security (2) SEO (5) Server Maintenance (4) Server Management (9) Social Media (1) Social Networking (2) Experiment (1) Software (9) Office (5) Visual Studio (12) Windows (4) Vista (1) SQL (1) SQL Server (13) Stored Procedure (1) Testing (1) The Site Doctor (106) Turnover Challenge (1) Twitter (2) uCommerce (1) Umbraco (18) 2009 (1) Web Development (57) WebDD (33) Wii (1)

Blog Archive

Search

<September 2010>
SunMonTueWedThuFriSat
2930311234
567891011
12131415161718
19202122232425
262728293012
3456789

Recent Comments

Blog Archive

Various Links

Blogs I Read

[Feed] Google Blog
Official Google Webmaster Central Blog
[Feed] Matt Cutts
Gadgets, Google, and SEO
[Feed] Ol' Deano's Blog
My mate Dean's blog on my space, equally as random as mine but not off on as much of a tangent!
[Feed] Sam's Blog
Sam is one of my younger brothers studying Product Design and Manufacture at Loughborough, this is his blog :) Enjoy!

Recent Tracks

last.fm - The Social Music Revolution

Disclaimer
The opinions expressed herein are my own personal opinions and do not represent my employer's view in any way.

newtelligence dasBlog 2.2.8279.16125

Send mail to the author(s) Email Me (Tim Gaunt)

© 2010 Tim Gaunt.

Sign In

    # Friday, April 17, 2009

    Quick ASP.Net tip: Half your page size in ASP.Net instantly

    Friday, April 17, 2009 3:53:05 PM (GMT Daylight Time, UTC+01:00)

    Ok it might be a little less than half side but it's near enough. I've been sitting on this for a while and needed to reference it for someone so I thought I'd post quickly about it. One of the most common complaints about .Net is that you have a lot of hidden "content" by the way of hidden inputs and the likes throughout your site. This can easily get corrupt on postback/slowdown the page load times etc.

    Really you should be optimising each control on the page (enabling/disabling where relevant) but if you want to cheat (lets face it, we all do):

    1. Download the files: PageStateAdapterv1.0.zip (3KB)
    2. Put PageStateAdapter.browser into your /App_Browsers/ folder (or create one and add it)
    3. Put TSDPageStateAdapter.dll into your website's /bin/ folder
    4. Load up your website and checkout your ViewState :)

    Incase you're interested in the source for it:

    PageStateAdapter.browser

    <browsers>
        <browser refID="Default">
            <controlAdapters>
                <adapter controlType="System.Web.UI.Page" adapterType="TheSiteDoctor.PageStateAdapter.PageStateAdapter" />
            </controlAdapters>
            <capabilities>
                <capability name="requiresControlStateInSession" value="true" />
            </capabilities>
        </browser>
    </browsers>

    PageStateAdapter.cs

    using System.Web.UI;

    namespace TheSiteDoctor.PageStateAdapter
    {
        public class PageStateAdapter : System.Web.UI.Adapters.PageAdapter
        {
            public override PageStatePersister GetStatePersister()
            {
                return new SessionPageStatePersister(this.Page);
            }
        }
    }

    The best example of how much this reduces ViewState by is when you add a large DataGrid to your site.

    Post files: PageStateAdapterv1.0.zip (3KB)

    Update: Apologies to those of you who downloaded and found it wouldn't compile, the .browser file was a little off (missing the second "PageStateAdapter"). I've updated it and changed the zip file download. Enjoy!

    Friday, April 17, 2009 8:08:26 PM (GMT Daylight Time, UTC+01:00)
    Nice!
    But doesn't moving the viewstate into session state result in replacing the bandwidth and page size problem with a server-side scaling problem?
    Chris
    Sunday, April 19, 2009 5:29:30 PM (GMT Daylight Time, UTC+01:00)
    Fair point but you could always just manage session with SQL Server in that instance no?
    Monday, June 08, 2009 9:54:52 PM (GMT Daylight Time, UTC+01:00)
    Greetings,

    I implemented similar code several months ago. Ever since upgrading to IE8. I see the viewState has returned when I view source Has anyone else experienced this? It appears to me this does not work in IE8 and the viewState is still included.

    I'm I seeing this correctly?

    Thanks,
    ned
    Wednesday, June 10, 2009 2:07:58 PM (GMT Daylight Time, UTC+01:00)
    Hi Ned,

    I've not noticed that at all, have you tried my code?

    Tim
    Name
    E-mail
    (will show your gravatar icon)
    Home page

    Comment (HTML not allowed)  

    Live Comment Preview