views:

123

answers:

1

I seem to keep running into these complex show/hide scenarios in ASP.NET web forms where the logic goes "if Field A equals blah, and Field B equals blahblah, then Field C is shown/hidden/validated/whatever." Before I run off and start building custom validators and custom controls so I can more easily manage it in markup or backend code, are there any libraries or simpler solutions I'm missing out there in the wild? jQuery makes the job easier, but I get the feeling I could abstract a lot of what I'm wrangling with out into a more elegant solution.

All of the controls that are dependent on each other or could trigger events are my own custom controls already, so I get the feeling I could start writing a small framework to handle it like so:

<my:DynamicShowHide runat="server">
    <PrerequisiteFields>
     <PrerequisiteField ControlId="FieldA" Value="blah" />
     <PrerequisiteField ControlId="FieldB" Value="blahblah" />
    </PrerequisiteFields>
    <DependentFields>
     <DependentField ControlId="FieldC" />
    </DependentFields>
</my:DynamicShowHide>

...that way if the Prerequisite values were both evaluated as true, the DependentField would show, and hide if not.

It seems (and feels) like I'm overengineering but I run into insanely large and complex decision trees like this more and more often. Anyone know of a better way or an existing library that does something along these lines?

+1  A: 

out of interest, in which particular instances do the use of decision trees most prominently arise?

For instance, I am guessing it is in most cases with dynamic data (data retrieved from a DB). And say the common usage for it would be in forms (or questionnaires) - hard to say as you have supplied examples of the usage of decsiion trees.

If these are the cases, then would it not be nice to handle all the stuff in the DB and populate the controls in the browser dynamically? You can set all the dependantUpon, and ansewrLeadsTo in the database, and the possible answers, and type of input control to generate, and it would lead to a much cleaner solution.

Granted the initial setup would be hard, but in the longterm, consider flexibility and maintenacne, and it should be okay.

waqasahmed