ASP.NET Masterpages and viewstate

I want to improve the performance of my site, not because it works poorly, but simply as a general exercise. The usual suggestion for asp.net sites is to remove the viewstate whenever possible. I believe that this can be done by each control on the page individually or for the entire page.

My question is: if I turn off the page view, this will stop the controls on the main page (as I understand it, the main page is actually a control on the page).

+3
source share
4 answers

Yes, the page is the source of the page flow. Thus, disabling the viewstate for the page brings the viewstate visualization out of the OnInit process. The best question would be, why turn off the view for the main page to do the same?

+1
source

There is an easy way to compress all of your viewstate.

Step 1. Create a new class that looks like this:

Imports System  
Imports System.Web.UI

Public Class SessionPageStateAdapter
    Inherits System.Web.UI.Adapters.PageAdapter

    Public Overrides Function GetStatePersister() As System.Web.UI.PageStatePersister

        Return New SessionPageStatePersister(Page)

    End Function
End Class

Step 2. Add a folder to the project App_Browsers.

Step 3. In the new folder, App_Browsersadd a new file default.browserthat looks like this. <browsers>
<browser refID="Default">
<controlAdapters>
<adapter controlType="System.Web.UI.Page" adapterType="[YourNamespaceGoesHere].SessionPageStateAdapter" />
</controlAdapters>
</browser>
</browsers>

, , . SessionPageStateAdapter viewstate , , . viewstate, - , , , .

+3

Source: https://habr.com/ru/post/1698254/


All Articles