Viewstate too large although Gridview enableviewstate false!


I am using a gridview to display data in my application. Everything works great, however, even though I put 'enableviewstate="false"' in the <asp:gridview> tag, I get a very big bloated viewstate, which is not really desirable. The gridview handles paging and is included in an <atlas:updatepanel>.

 I noticed that if I include no columns and just use


the viewstate is very small, as required. However, the moment I put in the bound and template fields, the viewstate becomes enourmous! Below there is a snippet of the code:

<atlas:UpdatePanel id="Panel2" runat="server">

<asp:GridView ID="gvGames" runat="server" AutoGenerateColumns="false" BorderColor="Lavender" Width="100%" EnableViewState="False" AllowPaging="true" Pagesize="30" CssClass="GamesGridTable" CellPadding="0" ForeColor="Black" CellSpacing="2" Font-Names="Verdana" Font-Size="10pt" EmptyDataText="No records found!" DataSourceID="objGamesDataSource" BorderStyle="Groove" GridLines="Horizontal">

<PagerStyle BackColor="Lavender" ForeColor="Black" HorizontalAlign="Left" />
<HeaderStyle BackColor="Lavender" Font-Bold="True" ForeColor="Black" BorderColor="Black" />
<SelectedRowStyle BackColor="LightBlue" ForeColor="Black" Font-Bold="True" BorderWidth="0px" />

<asp:BoundField DataField="Number" />
<asp:TemplateField HeaderText="Names">
<ControlStyle Width="2%" />
<HeaderStyle HorizontalAlign="Left" />


#Mid(CType(Eval("Name1"), String), 1, 40)%> <%#CheckELO(CType(Eval("ELO"),Integer)) %> - <%#Mid(Ctype(Eval("Name2"),String),1,40)%> <%#CheckELO(CType(Eval("ELO2"), Integer))%>


<asp:BoundField HeaderText="Location" ReadOnly="True" DataField="Location">
<ControlStyle Width="30%" />
<HeaderStyle HorizontalAlign="Left" />

<asp:BoundField HeaderText="Code" readonly="True" DataField="Code" />
<asp:BoundField HeaderText="Year" ReadOnly="True" DataField="Year">
<ControlStyle Width="3%" />
<HeaderStyle HorizontalAlign="Left" />

<asp:TemplateField HeaderText="Result">
<ControlStyle Width="2%" />
<HeaderStyle HorizontalAlign="Left" />
<%#GetResult(CType(Eval("Result"), Byte))%>


<RowStyle Height="20px" />

I do not understand why the viewstate is so big even though I explicitly disable it in the gridview tag! 

Thanks in advance for your help!


5/6/2007 12:56:54 PM 72751 articles. 3 followers. Follow

5 Replies

Similar Articles

[PageSpeed] 38

Is your gridview getting say 20 of 20,000 rows? There is an excellant article at Custom Paging in ASP.NET 2.0 with SQL Server 2005

That article shows how you can reduce dramaticly the size of recordsets to be retrieved to the website (which improves response time) and reduces dramatically the size of viewstate. 

Don't forget to click "Mark as Answer" on the post that helped you.
This credits that member, earns you a point and marks your thread as Resolved so we will all know you have been helped.
5/6/2007 3:03:34 PM

Hi Tatworth,

Thanks for your reply. Unfortunately, I had already referred to that article and I am already custom paging my gridview. You're right, I am having >20000 records. However, I do not see why I am getting its viewstate at all, as I have explicitly disabled the gridview viewstate. I am binding to an ObjectDataSource with my business object and returning 30 rows per page. I have also enabled caching.

Any help from here would be wonderful!

5/6/2007 5:12:25 PM

Hi, timothym

As I wrote ASP.NET always write Page hash key to view state. To disable this behavior you need to override page SavePageStateToPersistenceMedium and LoadPageStateFromPersistenceMedium functions and to disable the default Page behavior by not calling page base class. Those functions persist viewstate data in hidden field.

protected override void SavePageStateToPersistenceMedium(

object viewState)




protected override object LoadPageStateFromPersistenceMedium()


   return null;


I hope the above information will be helpful. If you have any issues or concerns, please let me know. It's my pleasure to be of assistance

Best Regards,
Rex Lin
Microsoft Online Community Support

If there is any question or the issue is not resolved, please feel free to mark the thread as not resolved
5/8/2007 2:44:58 AM

you mentioned that you've disabled gridview's viewstated what about the datasource ?

Kind Attn: If a reply to your post helped you, kindly mark it as Answered.
Please save Animals Help World Society For Protection Of Animals,
Protect these speechless creatures of GOD
5/8/2007 3:03:41 AM


Thanks for your replies.

I ran a trace on the page and found that there were 2 literals which had viewstate enabled and were consuming a lot of it! So I disabled their viewstate. Now, when I view the page trace, I see that the only significant storage in viewstate is the Gridview (15K), however, it is the "Control Viewstate" only that is taking that space. I do not know if it is possible to remove the Control Viewstate, maybe as Rex wrote.

As for your reply, satish_nadgev, I tried disabling the viewstate of the ObjectDataSource, however, then the page won't work and the DataSource is only taking 120 bytes, so I thought I'd leave it there. Thanks anyway!

5/8/2007 9:00:51 AM

Similar Artilces:

Huge ViewState in GridView even when EnableViewState=False
Hello, what can I do to reduce the ViewState in the GridView?I have EnableViewState=false and I have about 100 rows whithout paging.I also have this in my GridView-Code:...<asp:TemplateField ><ItemStyle wrap="False" horizontalalign="Right" /><ItemTemplate><asp:imagebutton runat="server" imageurl="edit.gif" alternatetext="Edit" commandname="edit"     causesvalidation="false" id="btnEdit"></asp:imagebutton><asp:imagebutton runat="server" id="btnDelete" imageurl="del.gif" alternatetext="Delete"     command...

Dot Net 3.5 causes Exception with GridView using EnableViewState = false
 Ever since I upgraded to .net 3.5, I've got some gridviews where the first time the page loads, they load fine, but on postback I get the following on any gridviews that have their EnableViewState set to false:  Exception Details: System.ArgumentException: Item has already been added. Key in dictionary: 'nslId'  Key being added: 'nslId'Stack Trace: [ArgumentException: Item has already been added. Key in dictionary: 'nslId' Key being added: 'nslId'] System.Collec...

Databinding on GridView cracks ViewState of controls containing in GridView
Hello, My problem is with GridView and is as follows: I have a GridView that has DataTable as its data source. There is also one unbound column containing check boxes, indicating which rows to delete when a Delete button on the form is clicked. In Delete button click event handler I remove selected rows from DataTable, rebind data on GridView. This works as expected. The problem comes when I want to disable header row when GridView is empty (contains zero rows). To do this I call myGridView.HeaderRow.Enabled = false. Actually this call does nothing and as a result I have the header enab...

gridview control in another gridview control
Hi ia have a questioni have a gridview control which contains button in one my question is i need another gridview to be placed in the  first gidviewso that when i click on the button the second gridview will populate the my question is how to place second gridview in first gridview.or is there any approach like first grid itself acting as parent and child.please help me  Hi sirikalavalapalli:                I think nested gridview will help you. Check this link and it will show you how...

Help Req: !!! :- On Disabling Controls Present inside a Gridview control
Hi All, We have A requirement Where we have disable controls inside a grid.These controls can be textbox, DropDownlist (in TemplateField), ComandField present inside the grid.We have to call a generic method for doing the same .(since it can be done for multiple grid.) PFB the code snippet we use. Which disables all the controls inside the page.The bolded part of the code is used to loop inside a grid view.(Not Working.)Is this ideal way to deal with the requirement.Or can someone suggest be a better way.        public void DisableMe(Page p1, st...

Gridview control embedded in another gridview control
I am writing an ambulance crew scheduling application on the web and I need some help completing the last part.  I have an access database that has three tables: user table, shift table (describing the shifts available), and a schedule table (that stores shift by shift_id and user by user_id).  I have a gridview control that will display the available shifts but I cannot get the embedded gridview control that will display the user that is signed up for each shift to display because I cannot figure out how to use the OnRowDataBound method.  I need a simple VB example of how to...

using javascript getting value from textbox when edit button is clicked and both controls are present in gridview control
Hi All using javascript I want to get value  from textbox when edit button is clicked and both controls that is texbox and button are present in gridview control .Alok Hi aloksinha83, Please see this post: Thanks,Qin Dian TangMicrosoft Online Community SupportPlease remember to mark the replies as answers if they help and unmark them if they provide no help....

Is ViewState still validated even when enableViewState="False" enableViewStateMac="False"
Does a aspx page get validated on the web server even if enableViewState="False" enableViewStateMac="False"? Thanks....   Pete A wrote: Does a aspx page get validated on the web server even if enableViewState="False" enableViewStateMac="False"? What do you mean by "Page get validated". Are you talking about the server side validation?Kumar Reddi If a web control depends on the ViewState (i.e. DropDownList) then you will have issues. So, you will also have issues with validation if ViewState is disabled.Ryan OlshanASPInsider | Microsoft MVP, ASP.NEThttp://ryanolshan...

Master Details in two seperate GridView Controls
I am simply trying to have a list of people in the top grid control (works fine), then when selected have the second Grid Control show details for that person(not working). Here is what I am trying from the load event: Sub BindData() Dim myConnection As New MySql.Data.MySqlClient.MySqlConnection(System.Configuration.ConfigurationManager.AppSettings("ConnectionSql")) Dim strPersonSQL, strActSQL As String strPersonSQL = "select row_id, first_name, last_name, middle_initial, dsi_id, created, created_by, program_of_study, email from tbl_person" Dim myPerCommand As New MySqlClient.MySqlComm...

Datagrid(.net 1.1) to GridView(.net 2.0) and using the RowUpdating event how to extract the values from the controls.
Ok  This is the settings: I use a Viewgrid with only itemtemplate colums for example. <asp:TemplateField HeaderText="Test"><ItemTemplate><asp:Label id="LBL_Test" text='<%# DataBinder.Eval(Container.DataItem, "Test1") %>' runat="server" meta:resourcekey="LBL_TestResource1"></asp:Label></font></ItemTemplate> <EditItemTemplate><asp:TextBox ID="HDN_Test" Text='<%# DataBinder.Eval(Container.DataItem, "Test1") %>' Runat="server" meta:resourcekey="HDN_TestResource1" /></EditItemTemplate></asp:TemplateField>  The ...

Data presentation control in another Data presentation control
 Hello,I want to make a menu with datalist or gridview control.Basically,the menu will be like this,Categories     Sub Categories.For example, for COMPUTING category there will be NOTEBOOKS DESKTOPS etc.There will be a image for CATEGORIES and linkbuttons with Subcategories.If I put a datalist inside a datalist and a link button inside the second datalist visually it satisfies my need.However,CommandArguments come from database to linkbutton.Andwhen one of these command buttons is cliked it must go to proper page.I dont know how to wrie an event_handler ,specifically, for...

There is a Gridview Control in the tmplate field of another GridView Control.
    For instance,a gridview displays the information of the  students in a class.A table is recording the information except their mark.There is another table recording the mark of the students whose foreign key is the primary key of the previous table.   string strSQLconnection=".................."; SqlConnection sqlCononection=new SqlConnection(strSQLconnection); SqlCommand sqlCommand=new SqlCommand("select * from stuendent where classID=1",sqlConnection); SqlConnection.Open(); SqlDataReader reader=sqlCommand.ExecuteReader(); GridVie...

i have work on gridview that i have as subject,bookname,link. in this some link column data are very large.according to that data(no spaces in that data)gridview has changed.i
hi,i have work on gridview that i have as subject,bookname,link. in this some link column data are very large.according to that data(no spaces in that data)gridview has changed.i want display half of the data and remaining display like this.(ex: can i display like this,and one more thing is always the column size will constant. Try something like this: <asp:templatefield headertext="Link"> <itemtemplate> <asp:hyperlink id="HyperLink1" runat="server" navigateurl='<...

ViewState for Visible=false controls?
Is there any viewstate information stored about a user control when its visible property is set to false?sun21170 yes. Setting the visible property to false will only make the control not render its html, but the viewstate will be saved any way, unless you set the EnableViewState to false.Wessam Zeidan If u still want to render the html and have then hidden u could Control.Attributes.Add("style","display: none"); to hide it and not make it invisible completely.Shravan Addaypally MCP What would be the difference between 'invisible' and 'display'?  Does 'display : none' ca...

Web resources about - Viewstate too large although Gridview enableviewstate false! -

Checklist: What NOT to do in ASP.NET
... Authentication and Session - Don't pass anything auth related in the query string. Cookieless auth will never be secure. Don't do it. EnableViewStateMac ...

Resources last updated: 1/16/2016 4:34:37 AM