Using .NET validators to do field dependencies

  • Thread starter Thread starter lorenzon
  • Start date Start date
L

lorenzon

I have a relatively simple case where I have a form with two fields
(call them A and B) which need to be enabled mutually exclusively
depending on the state of a drop down. So if drop down is "A" then
field A is populateable and if B then B.

This would be relatively simple to do with a CustomValidator I
imagine, but assuming I just wanted a serverside check, can anyone
think of a way of using say the CompareValidator or something to do
this check, even extending might be an option if it's less work than
writing the whole thing from scratch with a customvalidator..
 
What's wrong with simply using the .Enabled property of fields A and B during
the SelectedIndexChanged event of the drop-down list? Better yet, use
javascript to enable/disable the fields, so its all done client-side? Either
way, this doesn't sound like a task for the CustomValidator. The
CustomValidator control is basically a label that turns on/off based on
conditional logic you set up in the control's event.
 
Well a couple of reasons, firstly the validation rules are kept in a
business object that has no knowledge of clientside environments,
secondly I'm validating controls in an auto generated form in a grid
and don't want to have to explicitly hack in my own form to make this
work.

I've got everything sorted out except the rather crucial step of
finding a way to access other controls' values during the validation
(in the servervalidation delegate). There doesn't seem to be any way
to do that.
 
Back
Top