vote up 4 vote down star

Hi!

I want to disable a ASP.NET RequiredFieldValidator with JavaScript. Actually I'm using the following code:

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

This disables the validator. But my problem is, that I'm using a ValidationSummary. And this summary shows the validation message, even if I disable the validator.

Can someone tell me, how to disable the validator in the ValidationSummary too?

flag

Why not remove the validator all together ? – Ram Jan 27 at 17:17
I think Ram is right... you'll have to remove it altogether. – Bryan Jan 27 at 20:20

3 Answers

vote up 1 vote down check

The solution is to add a call to ValidationSummaryOnSubmit() after you disable the validator.

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

You can find a file called WebUIValidation.js on your development computer, which contains the client side JavaScript functions used by the ASP.NET validation process. The functions are well named and it's generally fairly easy to figure out what each of them do.

link|flag
Hey Jason! Thank you, I'll try it tomorrow. :) – Torben H. Jan 27 at 22:20
This works, thank you! – Torben H. Jan 28 at 11:49
vote up 0 vote down

Maybe you could try setting the EnableClientScript=true; and hide the summary by setting its css display style to none when you disable your validator. The summary is rendered as a div and is hidden when no summary is being displayed.

link|flag
This won't work. EnableClientScript only affects how the page is rendered...it's useless afterwards. Torben needs to disable the validator on the client-side. – Bryan Jan 27 at 20:19
vote up 0 vote down

Look at the javascript code generated for the validators on the client side. I believe you'll have to remove the validator spans from the "Page_Validators" array. The element ID will match the Validator ID.

This is just a theory. :) Let us know if it works, because I'm interested.

link|flag

Your Answer

Get an OpenID
or
never shown

Not the answer you're looking for? Browse other questions tagged or ask your own question.