E
Eric Maia
I have a textbox (StartDateTextBox) in a UserControl on my page, that
is supposed to have a date entered into it. I have a
RequiredFieldValidator that has its ControlToValidate property set to
the textbox. I also have a CompareValidator pointed to the textbox
with its Type="Date."
Despite all documentation to the contrary, I am getting an exception
when the page first loads that is thrown by the CompareValidator,
complaining that it cannot parse the empty string:
The value '' of the ValueToCompare property of 'StartDateValid' cannot
be converted to type 'Date'.
I am uncertain why this would be happening. I have composed the form
from a couple of user controls so I can reuse the same controls
separately on other pages. This UserControl has its set-up code
(determining which controls should be visible, the text of labels,
etc.) moved to a separate method which is called from Page_Load(). I
did this so the containing page can reset the control if it gets an
event from a different control.
Is the validation firing because the set-up code is not physically
within the Page_Load() method but is called from there? Even so, why
would the CompareValidator throw an exception instead of either
ignoring the empty value (which it is supposed to do) or setting its
IsValid property to false (which it should do if the value is in the
wrong format)?
Thanks - Eric
is supposed to have a date entered into it. I have a
RequiredFieldValidator that has its ControlToValidate property set to
the textbox. I also have a CompareValidator pointed to the textbox
with its Type="Date."
Despite all documentation to the contrary, I am getting an exception
when the page first loads that is thrown by the CompareValidator,
complaining that it cannot parse the empty string:
The value '' of the ValueToCompare property of 'StartDateValid' cannot
be converted to type 'Date'.
I am uncertain why this would be happening. I have composed the form
from a couple of user controls so I can reuse the same controls
separately on other pages. This UserControl has its set-up code
(determining which controls should be visible, the text of labels,
etc.) moved to a separate method which is called from Page_Load(). I
did this so the containing page can reset the control if it gets an
event from a different control.
Is the validation firing because the set-up code is not physically
within the Page_Load() method but is called from there? Even so, why
would the CompareValidator throw an exception instead of either
ignoring the empty value (which it is supposed to do) or setting its
IsValid property to false (which it should do if the value is in the
wrong format)?
Thanks - Eric