Solved

How requiredfieldvalidator only check one textbox in a aspx page with 6 textbox?

Posted on 2008-10-31
3
955 Views
Last Modified: 2012-06-27
I have 6 user control ascx pages, there is a textbox and submit button in each of them. I have a aspx page to include all those 6 user control pages.
I have a requiredfieldvalidator with onsubmit to check empty of all textbox. If the text box is empty and user clicks submit, it will be prompted.

Here is the aspx code

<asp:textbox id="text1" runat="server"></asp:textbox>
<asp:requiredfieldvalidator id="RequiredText1" runat="server" EnableViewState="False" ControlToValidate="text1" Display="None" ErrorMessage="Please input 1"></asp:requiredfieldvalidator>
<asp:validationsummary id="ValidationSummary" runat="server" EnableViewState="False" ShowMessageBox="True" ShowSummary="False"></asp:validationsummary>
<asp:button id="button1" runat="server" text="submit"></asp:button>

<asp:textbox id="text2" runat="server"></asp:textbox>
<asp:requiredfieldvalidator id="RequiredText2" runat="server" EnableViewState="False" ControlToValidate="text2" Display="None" ErrorMessage="Please input 2"></asp:requiredfieldvalidator>
<asp:validationsummary id="ValidationSummary" runat="server" EnableViewState="False" ShowMessageBox="True" ShowSummary="False"></asp:validationsummary>
<asp:button id="button2" runat="server" text="submit"></asp:button>

However, i just want to validate the onclick button, the remaining 5 textbox empty is ok. The code will prompt if one of six textbox is empty. So, I need to input text to all 6 textbox and it will not be prompted, how to solve it?

I use VC#

0
Comment
Question by:techques
3 Comments
 
LVL 5

Expert Comment

by:johnaryan
Comment Utility
There should be an extended property on all the TextBoxes that allows you to not fire the Validator. I think it's the CausesValidation property.
0
 
LVL 3

Expert Comment

by:biodooms
Comment Utility
So what you basically wish to do is submit if one of the 6 textboxes is filled? If that's the case then using an self made validation is the best solution.

do the following on button.click

if (!String.IsNullOrEmpty(Textbox1.Text) || (!String.IsNullOrEmpty(Textbox2.Text))
{
    //Do something
}
Else
{
    Errorlabel.visible = true;// The error label should be on the page with forcolor red and the error tekst.
    Errorlabel.databind();
}
0
 

Accepted Solution

by:
techques earned 0 total points
Comment Utility
add ValidationGroup="Control1" to textbox, button and validation summary

and it works
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

I recently went through the process of creating a Calendar Control of events with the basis of using a database to keep track of the dates that are selectable, one requirement was to have the selected date pop-up in a simple lightbox.  At first this…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

763 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

6 Experts available now in Live!

Get 1:1 Help Now