James
James

Reputation: 1876

What is the best way to manage Form state?

I'm developing a form in a C# .NET 2.0 application that contains complex logic regarding the state (enabled/disabled) of various controls on the form. (The design is a symptom of a business analyst's poor understanding of UI best practices.)

What would be the best way to go about managing the "state" of the form? Normally, I've seen an ShowControls(state) or SetEnables(state) function where state is enumeration of possible configurations (INITIAL, AFTER_SELECT, AFTER_COPY, etc). I predict that this will rapidly become unmaintainable.

What method of maintaining form "state" do you use? What patterns might you involve in keep track of complex control interaction?

Upvotes: 2

Views: 2872

Answers (2)

King Friday
King Friday

Reputation: 26086

You might consider alternative tactics with the business analyst to either discredit him or get him on your camp before proceeding as you are going down a black hole sounds like. Its best to win him on your side but it requires more patience. This may no be a technical issue.

But onto the technical discussion...

Since you are using web forms 2.0, ouch, you can use User Controls to encapsulate your form state using View State. You should use a top down approach. Let's assume you have 5 controls that control form state. Within each control you have a placeholder below that you can dynamically load things in and out based on the state of the controls. Within each User Control loaded in dynamically in you can do the Russian doll effect (encapsulation) and put more crazy rules in there the analyst randomly pulls out of his arse down the line. Encapsulation and ViewState are your friends in this case. Just be sure to load controls on Page_Init event as it will make all other events tie in well. I'm so sorry you are using web forms and .net 2.0. So sorry.

Upvotes: 0

Michael Meadows
Michael Meadows

Reputation: 28426

My favorite pattern is the passive view. It removes all state management responsibility from the form. In the end, it makes maintenance of your presentation code much easier, but there's some upfront cost in terms of additional code.

Upvotes: 3

Related Questions