Skip to content

Codepolice

  • ⤫

Using JQuery Validation plugin with ASP.NET

Posted by Judy Alvarez Posted on February 25, 2022March 1, 2022
0

Like everyone else, I’ve been playing around with JQuery a lot lately. Asp.net and JQuery are not the best friends in the world but I guess it will be a lot better when using ASP.NET MVC. Microsoft also announced that they will support JQuery natively in future versions. Nice!

If you want to learn more about ASP.NET and Jquery be sure to read both Rick Sthral’s and the Encosia blogs.

I’m working on a new project now where I am trying to stay away from asp.net ajax mainly because of performance reasons but also just because I want to learn something new. Today I’ve been using the JQuery Validation plugin.

There is a lot of documentation on how to use it on the documentation pages for the plugin but I want to share with you one thing that I had problems with.

This is some regular example code that all the samples use. The problem here is that for example “EmailTextbox” is not the ID of the control but the name.

$(document).ready(function() {
// validate signup form on keyup and submit
$("#aspnetForm").validate({
   rules: {
       OpenIdTextbox: "required",
       NicknameTextbox: {
          required: true,
          remote: "resources/nickname.aspx"
          },
       EmailTextbox: {
          required: true,
          email: true
          }
       }
    });
});

I scratched my head for a long long time when I used ctl00_ContentPlaceHolder1_EmailTextbox and nothing worked at all. So what you have to do is change this to something like this.

$(document).ready(function() {
 // validate signup form on keyup and submit
 $("#aspnetForm").validate({
     rules: {
         ctl00$ContentPlaceHolder1$OpenIdTextbox: "required",
         ctl00$ContentPlaceHolder1$NicknameTextbox: {
             required: true,
             remote: "resources/nickname.aspx"
         },
         ctl00$ContentPlaceHolder1$EmailTextbox: {
             required: true,
             email: true
         }
     }
 });
});

You could of course also use some method that rewrites the Control.UniqueID to a name and use <%= %> to get the name of the control.

Categories: JavascriptTagged: asp .net interview questions, asp net authentication, asp net controls, asp net core 1.0, asp net core logging, asp net core middleware, asp net core mvc tutorial, asp net developer, asp net features, asp net interview question, asp net interview questions for 10 years experience, asp net interview questions for 5 years experience, asp net là gì, asp net latest version, asp net machine account, asp net meaning, asp net mvc interview question, asp net mvc tutorial step by step for beginners with examples, asp net project, asp net projects, asp net session, asp net version, asp net web api tutorial, asp net web services, asp net webservice, difference between asp net and asp net core, learn asp net, session asp net, webservices in asp net, what is asp net core

Post navigation

Previous Previous post: Create a tag cloud with a limited amount of tags in ASP.NET and LINQ
Next Next post: Join and Group By with LINQ to Entities

Related Posts

  • What’s the story? JavaScript’s 30!

    #​764 — December 5, 2025 Read on the Web JavaScript Weekly 🎉  JavaScript Turns 30 Years Old  🎉 Back in May 1995, a 33 year old Brendan Eich built the first prototype of JavaScript in just ten days, originally codenamed Mocha (and then LiveScript). On December 4, 1995, Netscape and Sun Microsystems officially announced ‘JavaScript’ in a

    Posted by Posted on December 5, 2025
    0
  • Comparing performance across Node versions and ARM vs x86

    #​603 — December 2, 2025 Read on the Web Tinybench 6.0: A Tiny, Simple Benchmarking Library — Uses whatever precise timing capabilities are available (e.g. process.hrtime or performance.now). You can then benchmark whatever functions you want, specify how long or how many times to benchmark for, and get a variety of stats in return –

    Posted by Posted on December 2, 2025
    0
  • Algorithms visualized and demonstrated in JavaScript

    #​763 — November 28, 2025 Read on the Web JavaScript Weekly Over 150 Algorithms and Data Structures Demonstrated in JS — Examples of many common algorithms (e.g. bit manipulation, Pascal’s triangle, Hamming distance) and data structures (e.g. linked lists, tries, graphs) with explanations. Available in eighteen other written languages too. Oleksii Trekhleb et al. TypeScript: From

    Posted by Posted on November 28, 2025
    0
  • Guess who’s back, back again? Shai-Hulud.

    #​602 — November 25, 2025 Read on the Web How a Summer in Abruzzo Helped Bring Type Stripping to Node.js — Node.js TSC member and committer Marco tells the personal tale of what it took to bring type stripping (now considered stable) to Node. It’s neat to get the back story. He’s now working on

    Posted by Posted on November 25, 2025
    0
  • A significant Angular release

    #​762 — November 21, 2025 Read on the Web JavaScript Weekly Google Announces Angular v21 — The Google team has gone all out with this significant release of its popular JavaScript framework. They’ve put together a retro game-themed adventure-based tour of what’s new, along with top notch videos showing off features like its new signal-based

    Posted by Posted on November 21, 2025
    0
  • Did you know Node has a ‘deprecate’ method?

    #​601 — November 18, 2025 Read on the Web Node.js v25.2.1 (Current) Released (and 25.2.0 with Type Stripping Marked ‘Stable’) — v25.2.0 was released hours after we hit send last week (often the way!) and marked type stripping as stable, meaning all major server-side runtimes now support TypeScript officially (at least in type-stripping form). v25.2.1,

    Posted by Posted on November 18, 2025
    0
Judy Alvarez

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Codepolice

  • Github
  • Atlassian
  • Flatlogic
  • Xero
  • Jetbrains
  • Figma
  • What’s the story? JavaScript’s 30!
  • Comparing performance across Node versions and ARM vs x86
  • Algorithms visualized and demonstrated in JavaScript
  • Guess who’s back, back again? Shai-Hulud.
  • A significant Angular release
https://flatlogic.com/generator
COPYRIGHT © 2025 - Codepolice