Solved

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

Posted on 2008-10-31
3
956 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

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

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

In this Article, I will provide a few tips in problem and solution manner. Opening an ASPX page in Visual studio 2003 is very slow. To make it fast, please do follow below steps:   Open the Solution/Project. Right click the ASPX file to b…
One of the pain points with developing AJAX, JavaScript, JQuery, and other client-side behaviors is that JavaScript doesn’t allow for cross domain request for pulling content. For example, JavaScript code on www.johnchapman.name could not pull conte…
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …
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…

785 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