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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T15:17:07+00:00 2026-05-16T15:17:07+00:00

I have an ASP.NET page and I am trying to quickly match the validation

  • 0

I have an ASP.NET page and I am trying to quickly match the validation controls that are tied to a particular textbox (text input) using a jQuery selector. The validation controls render as a span and the “controltovalidate” property renders as an expando property. Here is a test example:

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>Untitled Page</title>
    <script type="text/javascript" src="jquery.js"></script>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
        <asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ControlToValidate="TextBox1"
            ErrorMessage="RequiredFieldValidator"></asp:RequiredFieldValidator>

        <asp:Button ID="Button1" runat="server" Text="Button" /></div>

        <input type="button" value="Test" onclick="ml_test();" />

        <script type="text/javascript">
            ml_test = function() {
                alert($('[controltovalidate=TextBox1]').get().length);
            };
        </script>

    </form>
</body>
</html>

Renders as:

(code removed here)

        <input name="TextBox1" type="text" id="TextBox1" />
        <span id="RequiredFieldValidator1" style="color:Red;visibility:hidden;">RequiredFieldValidator</span>
        <span id="RegularExpressionValidator1"></span>

        <input type="submit" name="Button1" value="Button" onclick="javascript:WebForm_DoPostBackWithOptions(new WebForm_PostBackOptions(&quot;Button1&quot;, &quot;&quot;, true, &quot;&quot;, &quot;&quot;, false, false))" id="Button1" /></div>

        <input type="button" value="Test" onclick="ml_test();" />

        <script type="text/javascript">
            ml_test = function() {
                alert($('[controltovalidate=TextBox1]').get().length);
            };
        </script>

(code removed here)

<script type="text/javascript">
//<![CDATA[
var RequiredFieldValidator1 = document.all ? document.all["RequiredFieldValidator1"] : document.getElementById("RequiredFieldValidator1");
RequiredFieldValidator1.controltovalidate = "TextBox1";
RequiredFieldValidator1.errormessage = "RequiredFieldValidator";
RequiredFieldValidator1.evaluationfunction = "RequiredFieldValidatorEvaluateIsValid";
RequiredFieldValidator1.initialvalue = "";
//]]>
</script>

The problem: the ml_test() function shows 1 in Internet Explorer 7 (as expected), but shows 0 in Firefox 3.6.8. I tried adding additional controls, but in Firefox it consistently doesn’t work.

I discovered this post that shows the use of an ampersand in the selector like this [@expando=value], but when I try this syntax, jQuery 1.4.2 throws an error.

Is there a cross-browser way to select expando attributes, and if so, what is the proper syntax?

  • 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-16T15:17:07+00:00Added an answer on May 16, 2026 at 3:17 pm

    You can use .filter() like this:

    ml_test = function() {
        alert($('span').filter(function() { return this.controltovalidate=='TextBox1'; }).length);
    };
    

    You can test it here, or make it a custom selector, like this:

    jQuery.expr[':'].validatorFor = function(o, i, m){
      return o.controltovalidate === m[3];
    };​
    

    And call it like this:

    ml_test = function() {
        alert($('span:validatorFor(TextBox1)').length);
    };
    

    You can that that version here.

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

Sidebar

Related Questions

I have an asp.net page that is trying to access a SSRS 2008 ReportServer
I have an ASP.NET MVC 3 site that I'm trying to enable client-side validation
I have a GridView on an ASP.NET page that I'm trying to bind to
I have an ASP.NET 4.0 page that I'm trying to reset to the top
I have an ASP.NET page that gets a list of game server ip addresses
I have an asp.net page with a c# code-behind. I am trying to have
I have this problem when trying to read a session in another asp.net page.
I am trying to create an ASP.NET page that connects to QuickBooks Online Edition,
I have an asp.net page that has some sort of data load problem. I'm
I have an asp.net page that needs to populate a treeview based on 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.