27 March 2013

"Turn OFF" The ViewState Please....

I was working on a small project using ASP.NET MVC few years ago.  I could not get rid of the GridView that time. GV became a very important tool in my ASP.NET web applications for years.

Some of my colleagues told me that I "should avoid" using the built-in toolbox if I don't want to suffer the consequences of VIEWSTATE!

So, I had to find ways how to Turn Off the ViewState as well as this "tiny" ControlState in my page. I found one good solution and it worked for me:


<%@ Page Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage"  EnableViewState="false"%>


//The ViewState and ControlState will not be saved and will become empty.

protected override void SavePageStateToPersistenceMedium(object state)
    {
    }



  
//ViewState will return null and empty.

protected override object LoadPageStateFromPersistenceMedium()
    {
        return null;
    }

No comments:

Post a Comment