Managing ViewState in WebFormsMVP

Yesterday I read a very good article about ViewState in ASP.NET.

We are currently using WebFormsMVP to provide the best testability in our project. The structure makes the anchor binding in OnInitComplete and relies heavily on DataBind expressions, for example.

<asp:Label Text="<%#Model.FirstName%>" runat="server" /> 

As I understand above, this will put Model.FirstName in the ViewState. Because data binding occurs late during the page life cycle when tracking in view mode is already enabled.

One option is to completely disable ViewState. Are there any others? Remeber, we cannot use OnInit or OnInitComplete, because OnLoad is the first event that hosts can handle.

Also keep in mind that I used the shortcut as an example. I am looking for a solution that will also work for complex controls.

Thank.

+3
source share
1 answer

After re-reading your question and related article, I believe that the best solution is to create your own set of custom controls, as suggested in the article. In this way, you can get your values ​​early in the management life cycle and reduce the injection of vision.

Very nice article, gives us something to think about, thanks for posting.

+2
source

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


All Articles