?
Solved

RequiredFieldValidator - one or the other

Posted on 2007-12-05
3
Medium Priority
?
616 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 2000 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

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

User art_snob (http://www.experts-exchange.com/M_6114203.html) encountered strange behavior of Android Web browser on his Mobile Web site. It took a while to find the true cause. It happens so, that the Android Web browser (at least up to OS ver. 2.…
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…
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …
Suggested Courses

752 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