Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Asp.Net ViewState performance

I am new to Asp.Net. I have a question about a viewstate control. Msdn says that it as a client-side state management but suggest that it can be disabled if there is big data on the page because of performance issues.

So, if this is a client-side state, how does it affect page load time of the site?

like image 698
Omer Avatar asked Mar 14 '23 22:03

Omer


2 Answers

For all the descriptions of what ViewState is and does, it all comes down to the fact that it is exactly one thing... ViewState is a bunch of data, serialized, base-64 encoded, and stuffed into an input type="hidden" element on the page.

Every time the page is rendered to the client, ViewState is sent to the client. Every time the client posts the form to the server, ViewState is sent to the server.

So, if ViewState contains, for example, 200KB of data then that's 200KB being sent back and forth with every request. 200KB of hidden information, unseen in the rendering of the page. Potentially unimportant data. (Basically, cruft.)

Does all of that data need to be sent back and forth with every request? It may be convenient once in a while, but does all of that state need to be managed with every request? Chances are, probably not. So you can tune the performance by not managing that state in the page and disabling ViewState appropriately for certain page elements.

Some state can be managed entirely server-side, some can be managed more implicitly in other page elements, some doesn't need to be managed at all. (Since web applications are designed to be stateless, that last option is ideal if you can manage it.)

like image 158
David Avatar answered Mar 28 '23 20:03

David


What is View State and How it Works in ASP.Net

A web application is stateless. That means that a new instance of a page is created every time when we make a request to the server to get the page and after the round trip our page has been lost immediately. It only happens because of one server, all the controls of the Web Page is created and after the round trip the server destroys all the instances. So to retain the values of the controls we use state management techniques.

http://www.c-sharpcorner.com/UploadFile/225740/what-is-view-state-and-how-it-works-in-Asp-Net53/

like image 45
Rae Lee Avatar answered Mar 28 '23 19:03

Rae Lee