I've spent several hours troubleshooting a crazy bug, which is explained in detail here. In a nutshell, the changed state of toolbar buttons (ASP.Net LinkButton controls) was not being kept. Every time a partial postback occurred on the web page, the changes would disappear.
I did much research and learned that the IPostBackHandler mechanism is what was responsible for restoring the control values after each postback. For some reason it didn't appear to be working. I even built a small test project but it did work in that!
Suddenly I noticed that the test page in my main project had EnableViewState=false. I changed it to true and ... everything worked fine!
My findings seem to conflict with several articles, including this one. All I know is that in my case EnableViewState must be set to true.
I'm posting this, both as a future reminder to myself and in the hopes that a State Management guru will read it and explain to me what's really going on.
Showing posts with label ViewState. Show all posts
Showing posts with label ViewState. Show all posts
Tuesday, June 16, 2009
Saturday, May 31, 2008
Turning Off ViewState
ASP.Net's ViewState functionality is an absolutely fantastic feature but is highly overused by many new web developers. The problem with it of course is that the more items that are stored, the more data is returned upon postback. Page sizes getting inflated and often for no particular good reason.
Most of my apps have [at least] these two common pages:
In both cases, the pages are very static - ie. display the data and that's it. So there's absolutely no need for any ViewState functionality. Yet on both I observed quite a bit. I don't know precisely where it was all coming from but I didn't want it there. At first I started adding EnableViewState="false" to various ASP.Net controls but then I learned that the quickest and most effective way would be to just add it to the very first line in the markup code, as follows:
<%@ Page Language="C#" MasterPageFile="~/main.master" AutoEventWireup="true" CodeFile="about.aspx.cs" Inherits="about" EnableViewState="false" %>
In my research I learned of a cool tool for deciphering ViewState data into something more meaningful. It's written by ASP.Net guru, Fritz Onion, and you can download it here.
Most of my apps have [at least] these two common pages:
- About
- View Error Log
In both cases, the pages are very static - ie. display the data and that's it. So there's absolutely no need for any ViewState functionality. Yet on both I observed quite a bit. I don't know precisely where it was all coming from but I didn't want it there. At first I started adding EnableViewState="false" to various ASP.Net controls but then I learned that the quickest and most effective way would be to just add it to the very first line in the markup code, as follows:
<%@ Page Language="C#" MasterPageFile="~/main.master" AutoEventWireup="true" CodeFile="about.aspx.cs" Inherits="about" EnableViewState="false" %>
In my research I learned of a cool tool for deciphering ViewState data into something more meaningful. It's written by ASP.Net guru, Fritz Onion, and you can download it here.
Subscribe to:
Posts (Atom)