?
Solved

RequiredFieldValidator - one or the other

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

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

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…
Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
This Micro Tutorial will teach you how to add a cinematic look to any film or video out there. There are very few simple steps that you will follow to do so. This will be demonstrated using Adobe Premiere Pro CS6.
Screencast - Getting to Know the Pipeline
Suggested Courses

807 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