What is the 'page lifecycle' of an ASP.NET MVC page, compared to ASP.NET WebForms?

Posted by Simon on Stack Overflow See other posts from Stack Overflow or by Simon
Published on 2009-01-20T04:38:47Z Indexed on 2010/03/26 4:43 UTC
Read the original article Hit count: 330

Filed under:

What is the 'page lifecycle' of an ASP.NET MVC page, compared to ASP.NET WebForms?

I'm tryin to better understand this 'simple' question in order to determine whether or not existing pages I have in a (very) simple site can be easily converted from ASP.NET WebForms.

Either a 'conversion' of the process below, or an alternative lifecycle would be what I'm looking for.

What I'm currently doing:

(yes i know that anyone capable of answering my question already knows all this -- i'm just tryin to get a comparison of the 'lifecycle' so i thought i'd start by filling in what we already all know)

Rendering the page:

  • I have a master page which contains my basic template
  • I have content pages that give me named regions from the master page into which I put content.
  • In an event handler for each content page I load data from the database (mostly read-only).
  • I bind this data to ASP.NET controls representing grids, dropdowns or repeaters. This data all 'lives' inside the HTML generated. Some of it gets into ViewState (but I wont go into that too much!)
  • I set properties or bind data to certain items like Image or TextBox controls on the page.
  • The page gets sent to the client rendered as non-reusable HTML.
  • I try to avoid using ViewState other than what the page needs as a minimum.

Client side (not using ASP.NET AJAX):

  • I may use JQuery and some nasty tricks to find controls on the page and perform operations on them.
  • If the user selects from a dropdown -- a postback is generated which triggers a C# event in my codebehind. This event may go to the database, but whatever it does a completely newly generated HTML page ends up getting sent back to the client.
  • I may use Page.Session to store key value pairs I need to reuse later

So with MVC how does this 'lifecycle' change?

© Stack Overflow or respective owner

Related posts about asp.net-mvc