Solved

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

Posted on 2008-10-31
3
958 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Enroll in May's Course of the Month

May’s Course of the Month is now available! Experts Exchange’s Premium Members and Team Accounts have access to a complimentary course each month as part of their membership—an extra way to increase training and boost professional development.

Question has a verified solution.

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

Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

739 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