dasran rajlui dasran rajlui - 14 days ago 3x
Vb.net Question

customvalidation, the field i needed only more than 0 and less than 366

Protected Sub cvActivationVoidTrxnDay_ServerValidate(ByVal source As Object, ByVal args As ServerValidateEventArgs) Handles cvActivationVoidTrxnDay.ServerValidate

If txtActivationVoidTrxnDay.Text > "0" And txtActivationVoidTrxnDay.Text < "366" Then
cvActivationVoidTrxnDay.ErrorMessage = "Please enter in between 0 to 366 days only."
args.IsValid = False
End If
End Sub

I need the field to be validated by only entering more than 0 or less than 366. i have tried this but i dont get the result.


You are trying to evaluate a range on strings, than will never work. You have to cast or convert the TextBox inputs to int


If Convert.ToInt32(txtActivationVoidTrxnDay.Text) > 0 And Convert.ToInt32(txtActivationVoidTrxnDay.Text) < 366 Then

Or you could use a range validator on the client side. But it's still wise to also validate in the backend in case client side javascript is disabled.