简体   繁体   中英

how to validate mulitple text boxes when user enters value in any one of the text box he can submit the form

I have multiple textboxes which im using for search query ,i want to validate them in such a way that if any one text box has value user can submit.

Can anyone suggest me ,how to do it .

Thanks

On your click event for the submit button, include some if/then statements that check all of the textboxes to see if they have acceptable values. If you just want to be sure that at least one box has data entered in it, then you could do this:

if (textBox1.Text != "" || textBox2.Text != "" || ...)
{
    // process form submission
}
else
{
    // inform user of missing data
}

If you are doing this client-side, in the web application, your best method will be to use JavaScript to perform the validation when the submit button is clicked. Otherwise the user will have to wait for the server to check the variables and get a new page.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM