Solved

Conditional validation in asp.net DetailsView

Posted on 2012-03-14
2
648 Views
Last Modified: 2012-06-21
I have a DetailsView I'm using to have users enter data. A couple of the fields have two validators. For example, a required field that also needs to be in a certain format. I don't want to show two error messages for one field.
I'm pretty sure this could be handled in the code behind but I'm not quit sure how to do it. (Sorry if it's messy, I wasn't sure how to include code in the message)
Here is an example of one of the fields I'm talking about
            <InsertItemTemplate>
              <asp:TextBox ID="jobNoTextBox" runat="server"
                  Text='<%# Bind("jobNo") %>' SkinID="TBInsert" MaxLength="7"          width="144px/>
              <asp:RequiredFieldValidator ID="jobNoRequiredFieldValidator" runat="server" ControlToValidate="jobNoTextBox" Display="dynamic"
                ErrorMessage="Job No is required" Width="112px"></asp:RequiredFieldValidator>
              <asp:CustomValidator ID="jobNoCustomValidator" runat="server" ClientValidationFunction="Min7Length" ControlToValidate="jobNoTextBox" Display="Dynamic" ErrorMessage="Job No is 7 characters in this format: 9999.99"
                Width="264px"></asp:CustomValidator>
            </InsertItemTemplate>

Thanks for any help on this
0
Comment
Question by:lakhi
2 Comments
 
LVL 26

Accepted Solution

by:
Anurag Thakur earned 500 total points
ID: 37723374
if the requirement is to have a required field and in a certain format and length then i will suggest you to use a required field and a regular expression (for length and format)

if the field is empty then only required will be fired and regular will not fire and it should work for you
0
 

Author Closing Comment

by:lakhi
ID: 37727128
Thanks!
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

Suggested Solutions

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.…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
This video discusses moving either the default database or any database to a new volume.
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…

744 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

12 Experts available now in Live!

Get 1:1 Help Now