c# – When I view Page Source of my aspx page in browser I see this – Education Career Blog

<form name="aspnetForm" method="post" action="/Web/Test.aspx" id="aspnetForm">

<div>
<input type="hidden" name="__EVENTTARGET" id="__EVENTTARGET" value="" />
<input type="hidden" name="__EVENTARGUMENT" id="__EVENTARGUMENT" value="" />
<input type="hidden" name="__VIEWSTATE" id="__VIEWSTATE" value="/wEPDwUKMTY1NDU2MTA1Mg9kFgJmD2QWAmYQZGQWDAIBDw8WAh4ISW1hZ2VVcmwFKGh0dHA6Ly9sb2NhbGhvc3Qvcm9zL2ltYWdlcy9yb3NfbG9nby5qcGdkZAIFDw8WAh4EVGV4dAUFTG9naW5kZAIHDw8WAh8ABS1odHRwOi8vbG9jYWxob3N0L3Jvcy9pbWFnZXMvaWNvbnMvUk9TbG9nby5wbmdkZAIIDw9kFgIeBWNsYXNzBQVXb21lbmQCDg9kFgICAQ9kFgJmDw8WAh4IR29hbFR5cGUFBUZlbW1lZBYCZg9kFgJmD2QWAgIBDxYCHwIFBm1lblRhYhYCZg8WAh4LXyFJdGVtQ291bnQCBBYKZg9kFgICAQ8WAh4Hb25jbGljawWUAWphdmFzY3JpcHQ6ZG9jdW1lbnQuZ2V0RWxlbWVudEJ5SWQoJ2N0bDAwX0NvbnRlbnRQbGFjZUhvbGRlcjJfY3RsMDBfSG9tZUJhbm5lcl9ycHRnb2FsQmFubmVyX2N0bDAwX2FuY1dlbGNvbWUnKS5ocmVmPSdodHRwOi8vbG9jYWxob3N0L3Jvcy93ZWxjb21lLydkAgEPZBYEAgEPFgIfBQWmAWphdmFzY3JpcHQ6Z

...........

and this ViewState’s value goes on and on and on……….

What on earth is this longggg value for ? How do I get rid of this …dont want it appearing in my Page source..something is apparently wrong

,

There’s nothing wrong.

The Viewstate is a special place where ASP.Net holds the values of all your ASP.Net controls so that the values will be remembered if the browser is refreshed or when you pass it along to other pages. You can also use it to store your own customer variables.

It slows down things a bit, and many have reported good results by disabling viewstate.

I program in ASP.Net MVC which doesn’t use the viewstate and I also don’t use Session to maximise the performance. Let me warn you though, that’s a difficult way to live.

This msdn article on viewstate will give you some more information about viewstate :

,

You can disable viewstate on the page level by setting the EnableViewState attribute to false.

<%@ Page EnableViewState="False" ... %>

You should make sure you don’t actually need viewstate – many of the ASP.NET server controls maintain their internal state using information stored in the viewstate.

Check this out for an article with more detailed info.

Leave a Comment