Groups | Blog | Home
all groups > asp.net webcontrols > march 2004 >

asp.net webcontrols : Comparevalidator in Datagrid


matt.torline NO[at]SPAM bissell.com
3/31/2004 8:24:22 AM
I am trying to use the LessThanEqual operator in a comparevalidator
validation control. The catch is that the comparevalidator is located
in a template column of a datagrid. I am comparing the value of the
datagrid column item against another textbox in the web form. For
some reason the page errors out and says that it cannot find the
controltocompare, I know that textbox is a vaild id for the
controltocompare. I did some testing by setting up a compare outside
the datagrid to another control using the same controltocompare source
and it worked just fine. I have even tried using a customvalidator
with the code below, but with no success. How do I compare a value
Matthew Torline
4/1/2004 2:21:20 AM
Thanks
Jeffrey

I did get a custom validator to work, its just that I was trying to
write less lines of code




*** Sent via Developersdex http://www.developersdex.com ***
v-jetan NO[at]SPAM online.microsoft.com (
4/1/2004 3:03:58 AM
Hi matt,

Based on my understanding, you nested your CompareValidator control in
DataGrid template column, you want to use these nested CompareValidator
control to validate a textbox control on the webform(Outside of DataGrid)

Actually, CompareValidator .ControlToValidate inherits from
BaseValidator.ControlToValidate, please view in MSDN below:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/
frlrfSystemWebUIWebControlsBaseValidatorClassControlToValidateTopic.asp

You will find:
"BaseValidator.ControlToValidate must be set to the ID of an input control
for all validation controls. The ID must refer to a control within the same
container as the validation control. It must be in the same page or user
control, or it must be in the same template of a templated control."

So you can not use nested CompareValidator to validate a textbox out of
datagrid.

Actually, a validator control is follow with the control you want to
validate, not follow with the control(or value) you want to compare. So if
you really want to validate that textbox, you should remove the validator
control outside of datagrid, in the same hierarchy as the TextBox control.

============================
Please apply my suggestion above and let me know if it helps resolve your
problem.

Thank you for your patience and cooperation. If you have any questions or
concerns, please feel free to post it in the group. I am standing by to be
of assistance.

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
AddThis Social Bookmark Button