473,396 Members | 1,755 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Validation for Two Textboxes

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.

--

Alphonse Giambrone
Email: a-giam at customdatasolutions dot us

Nov 18 '05 #1
3 1057
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.

--

Alphonse Giambrone
Email: a-giam at customdatasolutions dot us


User submitted from AEWNET (http://www.aewnet.com/)
Nov 18 '05 #2
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.)

Nov 18 '05 #3
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" <alan.washington@aew_nospam.com> wrote in message
news:%2****************@TK2MSFTNGP12.phx.gbl...
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.

--

Alphonse Giambrone
Email: a-giam at customdatasolutions dot us


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

Nov 18 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Kathy | last post by:
I have a form to generate a report. On the form are several textboxes and a "Generate" button. I would like to have the button grayed (not enabled), unless the data in each of the dependant...
1
by: Jason | last post by:
I have created a datagrid with several template columns and included validation controls in the template columns. I also have a button column with edit-update-cancel. When the datagrid item is...
1
by: mg | last post by:
How can I apply validation for date and currency on the values typed in EditItemTemplate TextBoxes in a DataGrid (C# WebForm)
5
by: KJ | last post by:
I need help. I have a checkbox and two textboxes on a webform. How can I validation if a person either enters something in the two textboxes OR the checkbox? I tried using a custom validator...
4
by: Craig G | last post by:
i have the following code for validating a textbox once a page posts, but the problem i am having is that the TextChanged event won't fire next time if the user does not change the value again ...
2
by: Shankar Mani via DotNetMonster.com | last post by:
Hi folks, I am facing a problem while using a DataGrid. I have a webform with a datagrid containing two text boxes for edit viz., countrycode and country name. Like wise I have two more text boxes...
1
by: Kris | last post by:
Hi, I have a DataGrid where in each row has couple of text boxes and an update button. Each row is dynamically generated as the number of rows are not known ahead of time. When the user clicks the...
12
by: NuB | last post by:
The validation controls are giving me a headache. here is what i'm trying to do and so far what I've tried has not worked. I need to hide my grid if the page is not valid how can i accomplish...
4
by: ibiza | last post by:
Hi all, I have a small question concerning asp.net 2.0 validation groups. I have this (simplified) situation : Name Value _____ _____ |_____| |_____| _____ _____...
12
by: Dabbler | last post by:
I need to insure that at least one of three phone number fields has a value (requiredfield) but I'm not sure of a way to implement this without server side logic. Is there a way to use the...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.