Managing ViewState in WebFormsMVP

742 views Asked by At

yesterday i read a very good article about ViewState in ASP.NET.

Currently we are using WebFormsMVP to allow better testability in our project. The framework does presenter binding in OnInitComplete and relies heavily on DataBind expressions e.g.

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

As i understand above article this would put Model.FirstName into ViewState. Because databinding happens late during page lifecycle when viewstate tracking is already enabled.

One option would be to disable ViewState altogether. Are there any other? Remeber, we can't use OnInit or OnInitComplete, because OnLoad is the first event presenters can handle.

Also keep in mind, that i used the label as example. I'm searching a solution that would also work for complex controls.

Thanks.

1

There are 1 answers

2
Jim Ross On

After re-reading your question and the article linked, I think the best solution is to create your own set of custom controls as suggested by the article. That way you can get your values in early in the control life-cycle and reduce the injection of viewstate.

Very good article, gives us some things to think about, thanks for posting.