Solved

Conditional validation in asp.net DetailsView

Posted on 2012-03-14
2
656 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
[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
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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

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 …
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…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…
Finding and deleting duplicate (picture) files can be a time consuming task. My wife and I, our three kids and their families all share one dilemma: Managing our pictures. Between desktops, laptops, phones, tablets, and cameras; over the last decade…

739 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