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

  • Everybody’s gone lintin’

    #​740 — June 13, 2025 Read on the Web JavaScript Weekly The State of React and the Community in 2025 — React continues to be a major dependency in the JavaScript world but recent innovations have led to much discussion about how it should move forward. Redux maintainer Mark Erikson gives an overview of React’s

    Posted by Posted on June 13, 2025
    0
  • Node 24.2, and some EOL warnings

    #​581 — June 10, 2025 Read on the Web PSA: Beware of End-of-Life Node.js Versions — Matteo Collina notes the Node.js ecosystem is “at a critical juncture”, with v18 and earlier now ‘End-of-Life’. He breaks down what that really means for users of legacy versions, and why you should skip Active LTS v20 and leap

    Posted by Posted on June 10, 2025
    0
  • TC39 advances numerous proposals at latest meeting

    #​739 — June 6, 2025 Read on the Web 🖊️ I was meant to be travelling this week. My plans changed, but I’d planned for a shorter issue, so enjoy the bitesize take! Back to full service next week. 🙂__Peter Cooper, your editor JavaScript Weekly ⚡ Announcing Rolldown-Vite — Rolldown is a fast Rust-based JavaScript bundler designed

    Posted by Posted on June 6, 2025
    0
  • PHP + Node: The odd couple of backend?

    #​580 — June 3, 2025 Read on the Web Seamlessly Blend PHP with Node.js — I bet some readers have strong feelings about the idea of mixing PHP and Node.js, but this is a neat project. php-node is a native module for Node that enables the running of PHP apps within the Node environment. Why?

    Posted by Posted on June 3, 2025
    0
  • How Remix is shaking things up

    #​738 — May 30, 2025 Read on the Web JavaScript Weekly Wake Up, Remix! Everything’s Changing.. — Big news from the Remix camp this week. About a year ago, Remix and React Router merged together reflecting their shared goals and code, but now it’s all change again. React Router is now basically what Remix originally

    Posted by Posted on May 30, 2025
    0
  • What the Node.js team has been discussing lately

    #​579 — May 27, 2025 Read on the Web 🖊️ I’m back from my week “off” attending Google I/O. Unfortunately there wasn’t much of relevance to Node, but it does give us two weeks of news to catch up on here 🙂__Your editor, Peter Cooper A Report From April’s Node.js Collaboration Summit — Twice a

    Posted by Posted on May 27, 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
  • Everybody’s gone lintin’
  • Node 24.2, and some EOL warnings
  • TC39 advances numerous proposals at latest meeting
  • PHP + Node: The odd couple of backend?
  • How Remix is shaking things up
https://flatlogic.com/generator
COPYRIGHT © 2025 - Codepolice