Solved

RequiredFieldValidator - one or the other

Posted on 2007-12-05
3
603 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 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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

In an ASP.NET application, I faced some technical problems. In this article, I list them out and show the solutions that I found.  I hope it will be useful. Problem: After closing a pop-up window, the parent page should be refreshed automaticall…
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 …
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…

860 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