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 7591189
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T20:35:28+00:00 2026-05-30T20:35:28+00:00

We often come into problems with .NET validators on elements that are hidden using

  • 0

We often come into problems with .NET validators on elements that are hidden using javascript/css (ie. display:none)

For example (there may be syntax errors but don’t worry about it)

<asp:CheckBox ID="chkNewsletter" runat="server" Checked="true" />
...
<div id='newsletterOnly'>
  <asp:TextBox ID="txtEmail" runat="server" />
  <asp:RequiredFieldValidator ID="vldEmail" ControlToValidate="txtEmail" ErrorMessage="Required" runat="server" />
</div>

with JavaScript:

$('#chkNewsletter').changed(function() {
  $(this).is(':checked') ? $('#newsletterOnly').show() : $('#newsletterOnly').hide();
});

It should not validate txtEmail if it is hidden.
You can’t submit the form if newsletterOnly is hidden, because the RequiredFieldValidator is still effective eventhough it is hidden 🙁
And you can’t even see the validator error message because it is hidden

Is there any way around this?

I am trying to avoid PostBacks to improve user experience.
I wish I could modify .NET javascript to validate controls only when they are visible.

  • 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-30T20:35:29+00:00Added an answer on May 30, 2026 at 8:35 pm

    I wrote this as a general solution (can be used on all .NET websites).

    You only need to add an OnClientClick to the submit button.

    //===================================================================
    // Disable .NET validators for hidden elements. Returns whether Page is now valid.
    // Usage:
    //   <asp:Button ID="btnSubmit" runat="server" Text="Submit" OnClientClick="DisableHiddenValidators()" />
    //===================================================================
    function DisableHiddenValidators() {
      for (var i = 0; i < Page_Validators.length; i++) {
        var visible = $('#' + Page_Validators[i].controltovalidate).is(':visible');
        ValidatorEnable(Page_Validators[i], visible)
      }
      return Page_ClientValidate();
    }
    

    To use it, simply include the above javascript and add the class OnClientClick="DisableHiddenValidators()" to the submit button:

    <asp:Button ID="btnSubmit" runat="server" Text="Submit" OnClientClick="DisableHiddenValidators()" />
    

    EDIT:
    jQuery $(submitButton).click function didn’t work on iPhone/Android. I have changed the sample code above slightly.

    If anyone see anything wrong or possible improvements please comment 🙂

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I often come across web applications that expose internal database primary keys through forms
When using JDBC, I often come across constructs like ResultSet rs = ps.executeQuery(); while
So we have a lot of routines that come out from exporting. We often
I've come into an interesting problem (as is often the case in interacting with
Something that I often run into with my users is their desire to aquire
I often run into a situation where I need to come up with a
You often need View in View. For example, a client that has many phone
On runtime, my code often come into an undefined method error for the method
I often come across clients that are asking for control-level permissions in web applications.
So I admit that I'm new to javascript and that I come from a

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.