CustomValidator not adding error to ValidationSummary

G

Guest

We want to require a value for CboCharity if the value for cboCardSource =
Fundraiser. Here's the client script:

<script language="javascript">
<!--
function ValidateCharity(source, arguments)
{
frmRegister.cboCardSource.IsValid = true;
if (frmRegister.cboCardSource.value == "Fundraiser")
{
if (frmRegister.cboCharity.value == "")
{
frmRegister.cboCardSource.IsValid = false;
}
}
}

//-->
</script>

Here's the CustomValidator:

<asp:customvalidator id="valFundraiser" runat="server"
ErrorMessage="A Fundraiser must be selected" Font-Size="X-Small"
Font-Names="Arial" ControlToValidate="cboCardSource"
ClientValidationFunction="ValidateCharity" Display="None">
</asp:customvalidator>

When the value of cboCardSource = "Fundrasier" and the value of cboCharity =
"" the ValidateCharity client script function runs and cboCardSource.IsValid
is set to false, however the validation summary never includes the error for
cboCardSource: "A Fundraiser must be selected". Why?
 
P

Peter Blum

The arguments parameter contains the IsValid property to set to true or
false. You are setting IsValid on the validator, not arguments.

function ValidateCharity(source, arguments)
{
arguments.IsValid = true;
if (frmRegister.cboCardSource.value == "Fundraiser")
{
if (frmRegister.cboCharity.value == "")
{
arguments.IsValid = false;
}
}
}

--- Peter Blum
www.PeterBlum.com
Email: (e-mail address removed)
Creator of "Professional Validation And More" at
http://www.peterblum.com/vam/home.aspx
 

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

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,020
Latest member
GenesisGai

Latest Threads

Top