CustomValidator not working in FormView

J

J. Cairn

I have tried everything and can't get the validation code to fire.
Code is below. I have simplified some of it to test it.


Here is the CustomValidator (it is in the InsertItemTemplate of my
FormView):
-----------------------------------------------------------------------------------------------------------------------------------------------
<asp:CustomValidator ID="CustomValidator1" runat="server"
ControlToValidate="DropDownList2"
ErrorMessage="You must make a lunch choice." ValidateEmptyText="True"
OnServerValidate="ValidatorTest_ServerValidate"></
asp:CustomValidator></td>
-----------------------------------------------------------------------------------------------------------------------------------------------


Here is the custom validation code. For testing, I set it to
automatically "fail".
-----------------------------------------------------------------------------------------------------------------------------------------------
Sub ValidatorTest_ServerValidate(ByVal sender As Object, ByVal
args As ServerValidateEventArgs)
args.IsValid = False
End Sub
-----------------------------------------------------------------------------------------------------------------------------------------------


Here is the code on the Submit button.
-----------------------------------------------------------------------------------------------------------------------------------------------
Sub btnSubmit_Click(sender as Object, e as EventArgs)
If Page.IsValid then
Response.Write("Page is valid")
Else
Response.Write("Page is not valid.")
End If
End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,581
Members
45,057
Latest member
KetoBeezACVGummies

Latest Threads

Top