Enable/Disable RequiredFieldValidator

A

Alphonse Giambrone

I am trying to enable/disable a requiredfieldvalidator on the client side
and am generating an error.
I had found some documentation on validation which states that I should be
able to enable/disable validators on the client side.

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnaspp/html/aspplusvalid.asp

According to it and the little other info I was able to find, the way to
accomplish what I want it to call ValidatorEnable on the client side to
enable/disable the validator.
As a test, I disabled the validator as the default and I am calling a
javascript function on page load which contains the following code:

strFocus="valrUserLoginF";
ValidatorEnable(strFocus, true);

With this, I receive a runtime error: 'style' is null or not an object.
valrUserLoginF is the declared id of the validator. I have also tried using
the clientid for it and get the same result.

How can I get the ValidatorEnable function to work?

Thanks for any help.
 
M

MSFT

Hi Alphonse,

We need to pass a object to ValidatorEnable, not a string. For example

ValidatorEnable(document.all("strFocus"), true);

hope this help,

Luke
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)
 
Joined
Mar 27, 2009
Messages
2
Reaction score
0
<%-- required field validator for FILE type --%>
<asp:RequiredFieldValidator ID="uploaderRequiredValidator"
runat="Server"
ControlToValidate="fileUploader"
ErrorMessage='<%# string.Format("{0} is required", Eval("name"))%>'
Enabled='<%#DisplayControl(Eval("type.id"),"file") && Convert.ToBoolean(Eval("required"))%>' />
<%-- regex validator for FILE type/extension --%>
<asp:RegularExpressionValidator ID="uploaderRegularExpressionValidator"
runat="server"
ControlToValidate="fileUploader"
ErrorMessage='<%# string.Format("{0} has invalid file format. Valid formats are {1}", Eval("name"), Eval("mask")) %>'
Enabled='<%#DisplayControl(Eval("type.id"),"file") && !string.IsNullOrEmpty((string)Eval("mask"))%>'
ValidationExpression='<%#GetFileLimitationExpression(Eval("mask")) %>'/>

<%-- required field validator for FILE type --%>
<asp:RequiredFieldValidator ID="uploaderRequiredValidator"
runat="Server"
ControlToValidate="urlUploader"
ErrorMessage='<%# string.Format("{0} is required", Eval("name"))%>'
Enabled='<%#DisplayControl(Eval("type.id"),"file") && Convert.ToBoolean(Eval("required"))%>' />
<%-- regex validator for FILE type/extension --%>
<asp:RegularExpressionValidator ID="uploaderRegularExpressionValidator"
runat="server"
ControlToValidate="urlUploader"
ErrorMessage='<%# string.Format("{0} has invalid file format. Valid formats are {1}", Eval("name"), Eval("mask")) %>'
Enabled='<%#DisplayControl(Eval("type.id"),"file") && !string.IsNullOrEmpty((string)Eval("mask"))%>'
ValidationExpression='<%#GetURLLimitationExpression(Eval("mask"))%>'/>


function toggleSelection(disableFileRQValidatorID,disableRExpValidatorID,enableFileRQValidatorID,enableRExpValidatorID){
if(disableFileRQValidatorID)
var rqControl = document.getElementById(disableFileRQValidatorID);
if(rqControl)
ValidatorEnable(rqControl,false);
if(disableRExpValidatorID){
var rExpValidator = document.getElementById(disableRExpValidatorID);
if(rExpValidator)
ValidatorEnable(rExpValidator,false);
if(enableFileRQValidatorID)
rqControl = document.getElementById(enableFileRQValidatorID);
if(rqControl)
ValidatorEnable(rqControl,true);
if(enableRExpValidatorID){
var rExpValidator = document.getElementById(enableRExpValidatorID);
if(rExpValidator)
ValidatorEnable(rExpValidator,true);
}


Con somebody help me with this i dont know what seems to be wrong i want to toggle validaters with radiobutton.



I am getting all the client IDs correctly in the JS function but dont know whats wrong i am unable to toggle validaters
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,774
Messages
2,569,599
Members
45,175
Latest member
Vinay Kumar_ Nevatia
Top