Whenever I make validation and assign the control to validation using ContorlToValidate.
But whenever the asp:label is connected to validation it still gives out this uncaught error.
“Sys.WebForms.PageRequestManagerServerErrorException: Sys.WebForms.PageRequestManagerServerErrorException: Control ‘labelID’ referenced by the ControlToValidate property of ‘validatorID’ cannot be validated.”
I have used CustomValidator, RegexValidator and requiredValidator.
the code goes like this.
`
<asp:GridView ......attributes......
<Columns>
<asp:TemplateField>
<ItemPemplate>
<div>
<asp:Label ID="labelIDn" runat="server" Text='<%# Eval("text") %>'
CssClass="txtSmall"></asp:Label>
<asp:CustomValidator ID="orderNumberValidator"
ClientValidationFunction="labelValidator"
ErrorMessage="validation failed"
ControlToValidate="grvTxtTransaction"
Display="Dynamic" runat="server" />
</div>
</ItemTemplate>
<Columns>
<asp:GridView>
there was more content in the gridview and I wrote down where I am trying validation.
I have tried onservervalidate too
and this is the validator for ClientValidationFunction
function Validator(sender, args) {
var val = args.value.toString();
if (val == null) {
args.IsValid = false;
} else {
var isInt = /^-?[0-9]*$/.test(args.value);
if (isInt) {
args.IsValid = true;
} else {
args.IsValid = false;
}
}
}
and when I try onserviervalidate, it still shares same loging but in c#
Tried different type of validation