Hello all,
I am using C#.net.
I have two textboxes (textbox1 / textbox2). If both are empty it needs to display a error message.
I tried a CustomValidator control and had it validating on textbox2. Within my code behind I checked whether both were empty if so it returned false (args = false). However when I built the application, it didn’t even access the button event. Can I not use this?
Here is what I have tried:
<asp:CustomValidator ID="customValidator" runat="server"
ErrorMessage="You must provide either a phone number or email address."
ControlToValidate="textbox2"
OnServerValidate="PhoneEmailCustomValidator_ServerValidate" />
protected void PhoneEmailCustomValidator_ServerValidate(object source, ServerValidateEventArgs args)
{
if (string.IsNullOrEmpty(texbox1.Text) && string.IsNullOrEmpty(textbox2.Text))
{
Debug.Write("Within if statement");
args.IsValid = false;
}
}
Thanks in advance for any help.
Clare