Click here to Skip to main content
16,016,134 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

I have four textboxes in my web page. I want to apply required field validator such that atleast one of the text box value is required,it is mandatory to have value in any one of the four . how to validate that.
Posted
Updated 27-Jan-10 20:12pm
v2

I would suggest you to write javascript code to achieve this:
Its pretty simple. Do something like this
function validateTextboxes()
        {
            if((document.getElementById('txtbox1').value == "") && (document.getElementById('txtbox2').value == "") && (document.getElementById('txtbox3').value == "") && (document.getElementById('txtbox4').value == ""))
            {
                alert('alert msg');
                return false;
            }
            
            else
            {
                return true;
            }
        }

Call the function onClientclick of button.. something like this:
OnClientClick="return validateData();"


On server side do the same checking before doing operations so that if javascript is diabled, validation is still performed.

Hope this helps!!!
 
Share this answer
 
You could also do server side validation without performing a full postback with the use of AJAX. See more here: ASP.NET Validation using Ajax.

Also, there are some extensions to the AJAX Control Toolkit that can do the same thing: AJAX Server-Side Validation.
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900