Click here to Skip to main content
15,867,141 members
Articles / Web Development / ASP.NET
Tip/Trick

Enable or Disable ASP.NET Validation on Client Side

Rate me:
Please Sign up or sign in to vote.
4.96/5 (19 votes)
2 May 2011CPOL 48.2K   14   11
How to enable or disable ASP.NET validation on client side

Introduction

Here is the solution to enable/disable ASP.NET validation using JavaScript.

Scenario: Suppose I have a dropdown which contains a list of Asian countries and Other when user is selecting Other than only txtOtherCity is enabled else disable, at that I disable the required field validation for Other city (rfvOtherCity).

JavaScript
//Syntax:
ValidatorEnable(ValidatorContronName,Boolean);
//Explanation:
ValidatorContronName:This is ClientID of the Validation control.
Boolean:true(Enable) or false(Disable)
//Example:
ValidatorEnable(document.getElementById('<%=rfvOtherCity.ClientID%>'), false);

Please provide a "Vote" if this would be helpfulRose | [Rose] .

Thanks,
Imdadhusen

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Technical Lead Infostretch Ahmedabad-Gujarat
India India
Aspiring for a challenging carrier wherein I can learn, grow, expand and share my existing knowledge in meaningful and coherent way.

sunaSaRa Imdadhusen


AWARDS:

  1. 2nd Best Mobile Article of January 2015
  2. 3rd Best Web Dev Article of May 2014
  3. 2nd Best Asp.Net article of MAY 2011
  4. 1st Best Asp.Net article of SEP 2010


Read More Articles...

Comments and Discussions

 
GeneralMy vote of 5 Pin
Savalia Manoj M7-Nov-12 1:10
Savalia Manoj M7-Nov-12 1:10 
GeneralRe: My vote of 5 Pin
Sunasara Imdadhusen22-Apr-14 3:10
professionalSunasara Imdadhusen22-Apr-14 3:10 
QuestionDefinition of ValidatorEnable? Pin
tahir.h4-Oct-12 2:35
tahir.h4-Oct-12 2:35 
AnswerRe: Definition of ValidatorEnable? Pin
Sunasara Imdadhusen4-Oct-12 2:59
professionalSunasara Imdadhusen4-Oct-12 2:59 
GeneralThanks, this is not appreciation! Pin
Sunasara Imdadhusen22-Aug-11 16:57
professionalSunasara Imdadhusen22-Aug-11 16:57 
GeneralReason for my vote of 1 to short. I would have preferred an... Pin
AbdullaMohammad22-Aug-11 3:15
AbdullaMohammad22-Aug-11 3:15 
GeneralRe: Reason for my vote of 1to short. I would have preferred an... Pin
Sunasara Imdadhusen22-Apr-14 3:10
professionalSunasara Imdadhusen22-Apr-14 3:10 
GeneralThanks for finding bug. Pin
Sunasara Imdadhusen2-May-11 22:55
professionalSunasara Imdadhusen2-May-11 22:55 
GeneralHi Sunasara, Fix the typo in last line of the code Validator... Pin
thatraja5-Mar-11 1:24
professionalthatraja5-Mar-11 1:24 
Hi Sunasara,
Fix the typo in last line of the code
ValidatorEnable(document.getElementById('<%=rfvOtherCity.ClientID%>'), fale);
It should be false
GeneralRe: Hi Sunasara,Fix the typo in last line of the codeValidator... Pin
Sunasara Imdadhusen22-Apr-14 3:11
professionalSunasara Imdadhusen22-Apr-14 3:11 
GeneralRe: Hi Sunasara,Fix the typo in last line of the codeValidator... Pin
thatraja22-Apr-14 3:13
professionalthatraja22-Apr-14 3:13 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.