Hello,
I am working in c# asp.net project. I have 4 to 5 pages.
I am using RequiredFiledValidator, RegilarExpressionValidator....etc on all pages.
But I want to use Jquery validation with common .js file with all validation in it and want to access it on all pages. So i can avoid code duplication on all pages.
Please suggest some example.
Also, can share Jquery or javascript all type of validation on page .
Thanks in advance!
Sushant TorankarPosted Oct 14, 2025, 6:43 PM
hello,
thanks for reply.
i tried, but it's not working, as i am using update panel i have only form tag in master page..
Sandhiya PriyaPosted Oct 13, 2025, 6:44 AM
How to Use Common jQuery Validation in All ASP.NET Pages
If you’re using multiple ASP.NET Web Forms pages (4–5 or more) and currently using
RequiredFieldValidator,RegularExpressionValidator, etc., you can replace those with a single common jQuery validation file to avoid repeating the same rules on every page.Step-by-Step Solution
1. Add jQuery and jQuery Validation plugin
Download or include these scripts in your Master Page (or each page if not using Master Page):
2. Create a common validation file (e.g.,
site-validation.js)Place it in your
Scriptsorjsfolder.3. Include this JS file on all pages
In your Master Page (recommended):
Now, every content page inside that master will automatically have jQuery validation enabled for matching control IDs.
4. Example ASPX Page
Because your control IDs are matched in the JavaScript rules (
txtName,txtEmail, etc.), validation works automatically across all pages.Advantages
Optional — Custom Common Validation Functions
You can even define reusable functions in your
site-validation.js:Then you can call these functions anywhere in your project.
Final Folder Structure Example
Output Behavior
When the user clicks Submit, if any field is empty or invalid:
Red error messages appear under the inputs.
Form won’t submit until all validations pass.
In Summary
To use jQuery Validation in all ASP.NET pages:
Add jQuery + validation plugin in Master Page.
Create one
site-validation.jsfile with all your validation rules.Include it globally.
Keep all field IDs consistent across pages.
Abhishek YadavPosted Oct 10, 2025, 7:13 AM
Step 1: Add jQuery Validation Library
Step 2: Create
common-validation.jsStep 3: Use It on Any Page