Solved

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

Posted on 2008-10-31
3
957 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
ID: 22848850
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
ID: 22849040
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
ID: 22850287
add ValidationGroup="Control1" to textbox, button and validation summary

and it works
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

820 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