Validation for Two Textboxes

  • Thread starter Thread starter Alphonse Giambrone
  • Start date Start date
A

Alphonse Giambrone

I have a page with two textboxes.
What would be a simple method of requiring entry for none or both?
In other words, it is ok to leave both empty, but an entry is made in one,
then the other must have an entry also.
 
You can use a custom validator control. For example:

1. add two textboxes to your form (textBox1 and textBox2)
2. add a custom validator controls (CustomValidator1)
3. double click on the CustomValidator1 and create the following:

private void CustomValidator1_ServerValidate(object source, System.Web.UI.WebControls.ServerValidateEventArgs args)
{

if(args.Value!=""&&TextBox2.Text=="")
{
args.IsValid = false;
}
else
{
args.IsValid = true;
}

}

This should be what you are looking for. Hope it helps.

Alan Washington
http://www.aewnet.com

I have a page with two textboxes.
What would be a simple method of requiring entry for none or both?
In other words, it is ok to leave both empty, but an entry is made in one,
then the other must have an entry also.

User submitted from AEWNET (http://www.aewnet.com/)
 
Hi Alphonse,

As for the problem you mentioned, I think the simplest means should be
write some custom client scripts to do the validation. Also, if it's
necessary to make a reusable component, you can consider building a cutsom
validation control.

If you have any other questions or ideas ,please feel free to post here.
Thanks.


Regards,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)
 
Thanks Alan, that works. All I need to do now is work out matching
javascript for client side.

--

Alphonse Giambrone
Email: a-giam at customdatasolutions dot us


alan.washington said:
You can use a custom validator control. For example:

1. add two textboxes to your form (textBox1 and textBox2)
2. add a custom validator controls (CustomValidator1)
3. double click on the CustomValidator1 and create the following:

private void CustomValidator1_ServerValidate(object source,
System.Web.UI.WebControls.ServerValidateEventArgs args)
 
Back
Top