Search code examples
sharepoint-2010web-partsviewstateconnection

Connecting Multiple Visual Web Parts and persisting the ViewModel


I currently have several web parts:

  1. EmailValidation
  2. PrimaryDetails
  3. AdditionalDetails

These are currently all connected together using similar logic to this and share a common RegistrationViewModel.

The issue is I use an Interface that holds all the values for the registration process and need these to be persisted across the web parts. In version 1 of the registration process I used a set of hidden values to hold the bits of information in between posts. We were hoping to get away from this approach and wondered if you knew of a tidier way to maintain state of an interface throughout the page calls. The issue is that each web part only has a portion of the fields on the form.

The only thing I could think of would be to store it in session data but a colleague didn’t sound keen on this due to the additional setup for that on all the servers.

Is there a way of getting the connections to maintain state across all posts?

EDIT: My issue with using hidden fields is simply that on all the web parts I need the 15+ fields so if you add or remove anything it makes maintenance a bit annoying.


Solution

  • Maybe you can put that information in a cookie.

    The hidden field solution doesn't seem bad, what is the exact problem with that?

    EDIT: based on the problem with the Hidden fields solution:

    You can have a class with the structure and serialize it into one single hidden field. If you need to add anything you just change the class and it will be replicated to the whole system. This is something similar to how the ViewState is implemented.