Jonas Bush

Blog.blog.blog.blog

  Home  |   Contact  |   Syndication    |   Login
  15 Posts | 0 Stories | 85 Comments | 18 Trackbacks

News

Archives

Post Categories

Image Galleries

General

If you ever find yourself needing to selectively disable an asp.net validator through javascript, you can do the following (in 2.0, not sure if this exists in 1.x):

function doSomething()
{
  var myVal = document.getElementById('myValidatorClientID');
  ValidatorEnable(myVal, false); 

}

Quick and easy! Sadly, not as easy to find through Google, so hopefully this post will help that. :)

posted on Friday, August 11, 2006 8:57 AM

Feedback

# re: Disabling an ASP.Net Validator through Javascript 8/14/2006 6:21 PM Paulo
Thanks!! :D

# re: Disabling an ASP.Net Validator through Javascript 8/18/2006 7:57 AM leandro koiti
you are the one! thanks a lot!

# re: Disabling an ASP.Net Validator through Javascript 9/1/2006 1:43 AM Zoria
it exists in 1.x
GREAT!!!!!!!THANKS!!!!

# re: Disabling an ASP.Net Validator through Javascript 10/10/2006 7:05 AM None
This is great. However, I would like to change the status of a control from invalid to valid rather than disable the validator. Any idea how I can do that?

# re: Disabling an ASP.Net Validator through Javascript 11/2/2006 10:37 PM Qazi
Great it works fine and best example so far, good work but be sure while getting the id of any control with this new master/content page setup.


# re: Disabling an ASP.Net Validator through Javascript 1/31/2007 9:49 PM Anand
It did not work for me. I had another solution of setting these three properties.

function disableValidator()
{
var myval = document.getElememtById('validator.ClientId');
myval.style.cssText="";
myval.style.display='none';
myval.style.accelerator=true;
}

It worked perfectly!!!

# re: Disabling an ASP.Net Validator through Javascript 5/4/2007 11:49 AM oola
Great... thaks

# re: Disabling an ASP.Net Validator through Javascript 5/7/2007 7:57 AM Naveed
wow wow wow

# re: Disabling an ASP.Net Validator through Javascript 5/18/2007 8:28 PM Frank Frenzel
Thanks, you just saved me so much time!

# re: Disabling an ASP.Net Validator through Javascript 6/3/2007 7:09 AM igal kakoon
as my mom always told me: "KISS"
keep it simple stupid


# re: Disabling an ASP.Net Validator through Javascript 8/22/2007 10:20 PM Sanjib Saha
Is it work on asp.net 1.x

# re: Disabling an ASP.Net Validator through Javascript 9/26/2007 8:57 AM frances
function doSomething()
{
var myVal = document.getElementById('fvr');
ValidatorEnable(myVal, false);
}

I do not know whether I understand the myValidatorClientID well. I put my validation control name there. since after the end user click the check box, the text box show up. I have the validation control for the text box enable.

# re: Disabling an ASP.Net Validator through Javascript 9/27/2007 9:29 PM Asim
The "ValidatorEnable" function i have used but it did't work, my problem is that i am using the dropdownlist and in the onchange event of the dropdown i have added client side script which check the specific value and on the bases of that value the regularexpressionvalidator enable/disable but my problme did't solved, i have tried many hours but :( no luchk any one can help me
thanks in advance

# re: Disabling an ASP.Net Validator through Javascript 9/29/2007 11:11 PM Deepak Aggarwal
Asim, if you are using a drop down and validation is not working set the CauseValidation property of the dropdown to true and it will start working.

The Problem with the posters solution. Even If the validation is disabled using the code, but the server throws back error for requirefieldvaldiator control. So the validator has to be handled on the server side as well.

# Re: Disabling an ASP.Net Validator through Javascript 10/1/2007 10:18 PM Asim Sajjad
Look my real scenario is that , i have dropdownlist which contain the value for the credit card type, mean visa, Master Card, discover and etc , and i have a text box in which user can enter the Credit Card number, when the "Visa" is selected from the dropdownlist then the regularexpressionValidator validate the text box value other wise not
thanks in advance

# re: Disabling an ASP.Net Validator through Javascript 10/31/2007 5:23 PM Tony
Thanks
worked for me in 1.1

# re: Disabling an ASP.Net Validator through Javascript 1/10/2008 9:27 AM bali
Thanx. Works great!!!!

# re: Disabling an ASP.Net Validator through Javascript 1/10/2008 9:27 AM bali
Thanx. Works great!!!!!!!!!!

# re: Disabling an ASP.Net Validator through Javascript 1/16/2008 5:33 AM Anish
Thanks yaar . ur really gr8

# re: Disabling an ASP.Net Validator through Javascript 1/20/2008 9:19 AM Liron Cohen
And it's the first one in Google now :)

# re: Disabling an ASP.Net Validator through Javascript 1/28/2008 8:23 AM Javier Callico
It worked for me too. Thanks.

# re: Disabling an ASP.Net Validator through Javascript 3/13/2008 7:25 AM George
Thanks! saved me lots of time

# re: Disabling an ASP.Net Validator through Javascript 4/1/2008 6:06 PM Rorigo
This is great, thanks, helped me a lot.

I hope this helps some of you who have their validators nested within other controls.

var myVal = document.getElementById('<%=Page.FindControl("myValidatorID").ClientID%>');

ValidatorEnable(myVal, true);

# re: Disabling an ASP.Net Validator through Javascript 4/19/2008 6:54 AM Anz
In the server the Page.IsValid will still be false.

http://www.FlickrMailer.com

# web project in asp.net 2.0 5/5/2008 2:25 AM Ashwani Dwivedi
I have created web project in visual studio 2.0 on my pc i work properly but when i open that project from other pc it gives error public token key etc how do i create project in share level sothat more than one user can work at a time on that project

# re: Disabling an ASP.Net Validator through Javascript 5/26/2008 10:07 PM Sonia
I have problem with ValidatorEnable(myval,true).
Problem is that when i enable the validator on some client event which even doesn't cause postback, validation error message is displayed to me.

# re: Disabling an ASP.Net Validator through Javascript 6/11/2008 1:03 PM kpg
you are a gawd

# re: Disabling an ASP.Net Validator through Javascript 7/24/2008 5:25 AM Rajasekhar
that's gr8


# re: Disabling an ASP.Net Validator through Javascript 8/1/2008 11:31 PM Vipul
The "ValidatorEnable" function i have used but it did't work, my problem is that i am using the dropdownlist and in the onchange event of the dropdown i have added client side script which check the specific value and on the bases of that value the regularexpressionvalidator enable/disable but my problme did't solved

i change CauseValidation property of dropdown then in server side pagr.isvalid give false then waht to do?
thanks in advance

# re: Disabling an ASP.Net Validator through Javascript 8/6/2008 4:23 AM vishal parekh
thanks,

thanks a lot

excellent work done,not just to findout it,but solution put like this straightforward ,

great, i searched google, and this is the firstlink i found.

again thank you very much.

# re: Disabling an ASP.Net Validator through Javascript 9/12/2008 11:07 AM phm
What i want to do is just enabling or disabling my validators on client side. But I want to keep the validation itself on server side.

I tried to use
- ValidatorEnable(validator, bEnabled);
in order to enabled / disabled on client script my validators.

It works for System.Web.UI.WeControls.RequiredFieldValidator validators, but it does not for my own validators, which derive from BaseValidator ...

Any idea?

# I have problem with the validation control inside update panel. 9/18/2008 5:34 AM Hari
I have 4 reqiuired field validation control inside a gridview which is inside an update panel. When i try to save the grid without enter any data it show the validation summary says that you have to enter values for these fields. But my problem is the error message show 4 times.. Anyone help me to figure my issue.. I am running out of time..

# re: Disabling an ASP.Net Validator through Javascript 9/22/2008 12:17 AM Hafiza
Its really gr8 .. but will this work if I call Page_ClientValidate();

# re: Disabling an ASP.Net Validator through Javascript 9/24/2008 3:39 AM Ivan
Thanks - just what I was looking for

# re: Disabling an ASP.Net Validator through Javascript 10/7/2008 5:52 AM Arsi
Thanks, first hit in google and just what i was looking for! :)

# re: Disabling an ASP.Net Validator through Javascript 10/18/2008 9:45 PM kk
How to disable entire validations on the page in one g0 through
javascript

# re: Disabling an ASP.Net Validator through Javascript 10/19/2008 2:43 AM Kago
THANKS MAN!

# re: Disabling an ASP.Net Validator through Javascript 12/5/2008 3:19 PM Karthikeyan
Does someone know how to fire required field validators in the client side on events other than the associated ones.

# re: Disabling an ASP.Net Validator through Javascript 12/5/2008 3:36 PM Jonas
Karthikeyan,

I addressed that in this blog post:

http://geekswithblogs.net/jonasb/archive/2007/01/29/104893.aspx

Thanks :)

BTW, I'm amazed to have this many comments so long after writing the post. :)

# re: Disabling an ASP.Net Validator through Javascript 1/26/2009 7:52 AM saikrishna
it didn't work for me

# re: Disabling an ASP.Net Validator through Javascript 2/26/2009 2:41 AM beck
u are absolutely right...

# re: Disabling an ASP.Net Validator through Javascript 3/26/2009 11:11 AM Cee Bee
This doesn't work ... :(

# re: Disabling an ASP.Net Validator through Javascript 3/31/2009 10:24 AM Tore Aurstad
omfg U are a LIFE SAVER!!!!!!!!!!


:-)

# re: Disabling an ASP.Net Validator through Javascript 4/6/2009 10:12 AM DesperateProgrammer
You made my day!

# re: Disabling an ASP.Net Validator through Javascript 4/13/2009 10:19 AM Umersh
You are too good

# re: Disabling an ASP.Net Validator through Javascript 4/22/2009 12:48 AM chetas
thanks. Really it's nice.

# re: Disabling an ASP.Net Validator through Javascript 4/26/2009 5:20 AM Rasha
veryyyyyyyyyyyyyy amazing

# re: Disabling an ASP.Net Validator through Javascript 4/26/2009 7:18 AM Muhammad Talal Shoaib
Thanks ...you are the best !!!!

# re: Disabling an ASP.Net Validator through Javascript 5/5/2009 8:00 PM Rizwan
It didn't work for me. I made sure I had the function name (ValidatorEnable) in correct case (if it was case-sensitive). I even put the alert() statements to make sure the code was being executed. I see that the code is being executed, but the validator is not disabled.

I finally resorted to use Custom Validator and took care of conditional validation in ServerValidate event.


# re: Disabling an ASP.Net Validator through Javascript 6/8/2009 7:35 AM Mohamed Adel Elkhodary
You can use the enabled property of the validators. It works for me in dot net framework 2.0

var requiredFieldValidatorPrice = document.getElementById("<%= requiredFieldValidatorPrice.ClientID %>");
requiredFieldValidatorPrice.enabled = true;

I hope It helps

Post Feedback

Title:
Name:
Email: (never displayed)
Url:
Comments: