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

  • Playwright now offers a UI mode

    #​631 — March 24, 2023 Read on the Web JavaScript Weekly Speeding Up the JavaScript Ecosystem: npm Scripts — The latest in what has been a fascinating series on finding ‘low hanging fruit’ when it comes to performance in the JavaScript world. The author explains it best himself: “‘npm scripts’ are executed by JavaScript developers

    Posted by Posted on March 24, 2023
    0
  • Everyone’s coming for Node.js this week

    #​479 — March 23, 2023 Read on the Web 🔒  npm Granular Access Tokens Now Generally Available — The granular access token feature on the npm registry is now generally available, allowing you to restrict token access to specific packages, set expiration dates, limit access by IP range, and more. GitHub Automatic npm Publishing with GitHub

    Posted by Posted on March 23, 2023
    0
  • Transformers: JavaScript in Disguise

    #​630 — March 17, 2023 Read on the Web JavaScript Weekly 🤖  Transformers.js: Running ML Models in the Browser — Transformers are a type of machine learning model often used for natural language or visual processing and while running such models directly in the browser is in its infancy, Transformers.js opens up some ML models

    Posted by Posted on March 17, 2023
    0
  • Shell-free scripting from Node

    #​478 — March 16, 2023 Read on the Web Shell-Free Scripts with Execa 7.1 — Execa is a popular process execution library for Node and the latest version includes an interesting $ method feature for writing zx-style scripts with it, making it even more useful for shell scripting style usecases. ehmicky Turbowatch: File Change Detector and

    Posted by Posted on March 16, 2023
    0
  • New JavaScript features of the past few years

    #​629 — March 10, 2023 Read on the Web JavaScript Weekly JavaScript Features from the Past Few Years — Packed with examples, this post tackles the changes and tweaks to JavaScript and TypeScript over the past several years (some as far back as ES6/ES2015, like tagged template literals). Linus Schlumberger Astro’s 2023 Web Framework Performance Report —

    Posted by Posted on March 10, 2023
    0
  • Taking flight with Feathers 5

    #​477 — March 9, 2023 Read on the Web Feathers 5: The API and Real-Time App Framework — Feathers isn’t as well known as Nest or Fastify, say, but it’s a powerful and mature option if you want to spin up a Node CRUD app tied to a database and now it’s “TypeScript all the

    Posted by Posted on March 9, 2023
    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
  • Playwright now offers a UI mode
  • Everyone’s coming for Node.js this week
  • Transformers: JavaScript in Disguise
  • Shell-free scripting from Node
  • New JavaScript features of the past few years
https://flatlogic.com/generator
COPYRIGHT © 2023 - Codepolice