Client side validator reset?

  • Thread starter Thread starter Paul
  • Start date Start date
P

Paul

How do you clear a validation control on the client?
I have a clear button which clears the input boxes, but if any validation
controls have fired, their text isn't cleared. I looked around for a long time
for an answer but found nothing. Has to be cleared on the client with no postback.
 
It sounds like you just want to clear the text of the validation control. If
that's the case, you want to write a javascript routine similar to this (I
apologize if innerHtml isn't the name of the property, but you'll get the
idea):

function clearValidation ()
{
document.getElementById("ValidatorControlName").innerHtml = '';
}

You will then want to call this method on whatever event you're handling
that is supposed to clear this. If a simple button click:

<input type="button" onClick="js:clearValidation()">
 
You can also call ValidatorEnable(validatorname, false);

false turns the validator off. True turns it back on.
 
That was the first thing I tried and it doesn't work, nor does innerText.

document.getElementById("RequiredFieldValidator2").innerHtml = '';

Validation control as rendered -- with visibility:hidden? It still shows up on
the page.

<span id="RequiredFieldValidator2" style="color:Red;visibility:hidden;">File
Name cannot be empty.</span>
 
Ok, now it's working as:

document.getElementById("RequiredFieldValidator2").innerHtml = '';

I made no changes but now it works. ValidatorEnable also works. I am trying to
do too much client side on this page, I think I will have to go to codebehind
and separate pages.
 
Back
Top