Validation for Two Textboxes

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.
 
A

alan.washington

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/)
 
S

Steven Cheng[MSFT]

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.)
 
A

Alphonse Giambrone

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)
 

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

Forum statistics

Threads
473,755
Messages
2,569,539
Members
45,024
Latest member
ARDU_PROgrammER

Latest Threads

Top