Field Validation - Can you tell me what I'm doing wrong?

  • Thread starter Thread starter Martin
  • Start date Start date
M

Martin

Dear Group

Instead of placing Field Validators on the Form, I would like them to
create programatically but get an 'Object reference not set to an
instance of an object.' error. Following the sample code. I'm grateful
for any hints!

Thanks for your time and efforts!

Martin

Private Sub Submit()

Dim FVal1 As New RequiredFieldValidator

FVal1.ControlToValidate = "FirstnameTxt"
FVal1.Validate() '---It fails in this line
If FVal1.IsValid = False Then
Label1.Text = "You need to Provide a Firstname!"
Exit Sub
End If

...

End Sub
 
Hi,

the validator can't locate the control to be validated unless it is added to
the Controls collection.

--
Teemu Keiski
MCP, Microsoft MVP (ASP.NET), AspInsiders member
ASP.NET Forum Moderator, AspAlliance Columnist


Dear Group

Instead of placing Field Validators on the Form, I would like them to
create programatically but get an 'Object reference not set to an
instance of an object.' error. Following the sample code. I'm grateful
for any hints!

Thanks for your time and efforts!

Martin

Private Sub Submit()

Dim FVal1 As New RequiredFieldValidator

FVal1.ControlToValidate = "FirstnameTxt"
FVal1.Validate() '---It fails in this line
If FVal1.IsValid = False Then
Label1.Text = "You need to Provide a Firstname!"
Exit Sub
End If

...

End Sub
 
Back
Top