Solved

RequiredFieldValidator - one or the other

Posted on 2007-12-05
3
596 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:BobCSD
3 Comments
 
LVL 14

Accepted Solution

by:
chinu1310 earned 500 total points
Comment Utility
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
Comment Utility
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 1

Author Closing Comment

by:BobCSD
Comment Utility
Perfect! Works like a charm!
0

Featured Post

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

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…
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 is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

762 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

Need Help in Real-Time?

Connect with top rated Experts

6 Experts available now in Live!

Get 1:1 Help Now