Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6193691
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T03:09:51+00:00 2026-05-24T03:09:51+00:00

So I have a custom validator that is working only partially. It basically has

  • 0

So I have a custom validator that is working only partially. It basically has two things it’s checking for: if two fields are filled out, and whether or not what has been entered in those fields already exists in the database. Checking against the database is working fine, but checking whether or not the fields are filled out is not. I don’t want to use required field validators, since I want the error messages all in the exact same location on the page. I’m pretty sure I just messed up on something simple, but I just can’t find it.

<strong>Course Prefix and Number:</strong>
<asp:TextBox ID="txtCoursePrefix" runat="server" Width="45" MaxLength="4" CssClass="caps"></asp:TextBox>
-
<asp:TextBox ID="txtCourseNum" runat="server" Width="45" MaxLength="6" CssClass="caps"></asp:TextBox>
<span class="required">*
<asp:CustomValidator ID="cvDuplicate" runat="server" ControlToValidate="txtCoursePrefix" ValidateEmptyText="true"></asp:CustomValidator>
</span>

Code behind:

'Check if fields have been filled out
    If txtCoursePrefix.Text Is Nothing Or txtCourseNum.Text Is Nothing Then
        cvDuplicate.ErrorMessage = "Required"
        args.IsValid = False
    End If
'Code that checks values against database goes here
'If matching record does not exist...
    If myValue IsNot Nothing Then
        cvDuplicate.ErrorMessage = "Course number is already taken."
        args.IsValid = False
    End If

So once again it is the first part that’s not working, the second part is working fine.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T03:09:51+00:00Added an answer on May 24, 2026 at 3:09 am

    It might be that the Text box is considered an empty string, not Nothing. Try this for your check:

    If String.IsNullOrEmpty(txtCoursePrefix.Text) Or String.IsNullOrEmpty(txtCourseNum.Text) Then
        cvDuplicate.ErrorMessage = "Required"
        args.IsValid = False
    End If
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a custom plugin (I didn't write it) that is not working on
I have a large multi-directional form that validates almost all fields with Jquery Validator,
I have a custom control that inherits from WebControl and implements IValidator, but I
I have a few models that need to have custom find conditions placed on
I have a custom control that implements IPostBackEventHandler. Some client-side events invoke __doPostBack(controlID, eventArgs).
I have a form that has a Is you billing address the same as
I have a very large Form with many date fields that need to be
I have two fields representing data range (from and to). I need to check
I am working on implementing a custom membership provider that works against an existing
Hello I am working with an application that already has a few validation criterion,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.