Webforms -> ViewModel - Pageload

To get the convertions to DotVVM done you need to learn how the ViewModel concept works. I mean this is the same hurdle you need to overcome if you want to rewrite your project into Blazor, which I refused of doing because there is DotVVM which I like better.

Anyway I checked the documentation, the YouTube videos but I didn’t find anything on how to simply convert this to DotVVM:

protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
// do something
}
}

Handling Buttons convertions you are showing in the videos. But not the initial on load page.
Maybe this is something for the cheat sheet or the missing “Plan of modernization”

Assuming you want to place this method into the ViewModel class:

  • Make sure the class inherits from DotvvmViewModelBase
  • Override the Load method
public override async Task Load()
{
   ...
   if (this.Context.IsPostBack)
       ...
   await base.Load()
}

There are also Init and PreRender events which you can override. Usually, we load data in the PreRender event (naming :man_facepalming:), but please check the ViewModel docs for more details: Overview | DotVVM Documentation (especially the page lifecycle, bottom of the page)

It’s a great point that this could be added to the Cheat-sheet. I’ll do it when I have some time.