Solved

RequiredFieldValidator - one or the other

Posted on 2007-12-05
3
610 Views
Last Modified: 2012-06-21
I have two fields on my PasswordRecovery control (template)... I don't want to require both, either one or the other. How do I do that? Is there a way to do it with the RequiredFieldValidator's? I don't see it in the properties.

                               <tr>
                                    <td align="right">
                                        <asp:Label ID="UserNameLabel" runat="server" AssociatedControlID="UserName">Alias:</asp:Label></td>
                                    <td align="left">
                                        <asp:TextBox ID="UserName" runat="server"></asp:TextBox>
                                        <asp:RequiredFieldValidator ID="UserNameRequired" runat="server"
                                            ControlToValidate="UserName" ErrorMessage="Alias or Email is required."
                                            ToolTip="Alias or Email is required." ValidationGroup="PasswordRecovery1"
                                            ForeColor="DarkRed">*</asp:RequiredFieldValidator>
                                        <asp:Button ID="SubmitButton" runat="server" CommandName="Submit"
                                            Text="Submit" CssClass="buttonstyle" ValidationGroup="PasswordRecovery1" />
                                    </td>
                                </tr>
                                <tr>
                                    <td align="right">
                                        <asp:Label ID="EmailLabel" runat="server" AssociatedControlID="Email">Email Address:</asp:Label></td>
                                    <td align="left">
                                        <asp:TextBox ID="Email" runat="server"></asp:TextBox>
                                        <asp:RequiredFieldValidator ID="EmailRequired" runat="server"
                                            ControlToValidate="Email" ErrorMessage="Alias or Email is required."
                                            ToolTip="Alias or Email is required." ValidationGroup="PasswordRecovery1"
                                            ForeColor="DarkRed">*</asp:RequiredFieldValidator>
                                        <asp:Button ID="SubmitButton1" runat="server" CommandName="Submit"
                                            Text="Submit" CssClass="buttonstyle" ValidationGroup="PasswordRecovery1" />
                                    </td>
                                </tr>
 
0
Comment
Question by:Starr Duskk
[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 14

Accepted Solution

by:
chinu1310 earned 500 total points
ID: 20415569
check this out.

<asp:FileUpload id="FileUpload1" runat="server"/>
<asp:requiredfieldvalidator ID="rfv1" ValidationGroup="Group1" ErrorMessage = "Need to Fill in Value!" ControlToValidate= "FileUpload1"
             runat="server"/>

 

<asp:FileUpload id="FileUpload2" runat="server"/>
<asp:requiredfieldvalidator ID="rfv2" ValidationGroup="Group2" ErrorMessage="Need to Fill in Value!" ControlToValidate= "FileUpload2"
            runat="server"/>


            <asp:button ID="btnFileUpload1" Text="FileUpload1" ValidationGroup="Group1" runat="server" OnClick="FileUpload1_Click"/>
           <asp:button ID="btnFileUpload2" Text="FileUpload2" ValidationGroup="Group2" runat="server" OnClick="FileUpload2_Click"/>

Creating a validation group which will allow you to have any one of them to be validated.

Ref:
http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=2223431&SiteID=1

Hope it helps
0
 
LVL 10

Expert Comment

by:Alpesh Patel
ID: 20415611
No you can not do it with Validator control
but u can do it with Javascript function

on your button

<asp:button id="abc" runat="server" onClientClick="javascript: return validate();" />
here your javscript function validate will return true or false for submit event and also javascirpt function set message on the client side
thanx
0
 
LVL 2

Author Closing Comment

by:Starr Duskk
ID: 31412973
Perfect! Works like a charm!
0

Featured Post

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

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…
ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.

707 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