CustomValidator server-side

N

Next

Hi,

I want to use the CustomValidator control as follows:

<asp:label id="LabelQuantity" runat="server" ToolTip="Enter a quantity
greater than or equal to the minimum order"
Font-Bold="True">Quantity</asp:label>
<asp:requiredfieldvalidator id="RequiredFieldValidatorQuantity"
runat="server" ControlToValidate="Quantity" ErrorMessage="Required Field"
Display="Dynamic">Required</asp:requiredfieldvalidator>
<asp:CompareValidator id="CompareValidatorQuantityInt"
Operator="DataTypeCheck" Type="Integer" runat="server"
ControlToValidate="Quantity" ErrorMessage="Enter whole number"
Display="Dynamic">Enter whole number</asp:CompareValidator>
<asp:CompareValidator id="CompareValidatorQuantityPos"
Operator="GreaterThan" Type="Integer" ValueToCompare="0" runat="server"
ControlToValidate="Quantity" ErrorMessage="Enter positive number"
Display="Dynamic">Enter positive number</asp:CompareValidator>
<asp:CustomValidator id=CustomValidatorQuantity runat="server"
Display="Dynamic" ErrorMessage="Invalid Increment"
ControlToValidate="Quantity" ClientValidationFunction="CheckQuantity"
OnServerValidate="QuantityIncrementCheck">Invalid
Increment</asp:CustomValidator>

However I get this error if and include the OnServerValidate attribute:

"External component has thrown an exception."

If I exclude the OnServerValidate attribute the page works just fine. Why
would this attribute cause such an error?
Any help or suggestions would be appreciated.
I don't even know where to begin to debug this kind of error. Page breaks in
the Page OnInit() don't work.

------Client-Side:---------------
function CheckQuantity(sender, args)
{
var increments =
document.getElementById("MinimumQuantityIncrement").innerHTML;
increments = parseInt(increments.split(" ")[0]);

var qty = parseInt(args.Value);
if (qty % increments == 0) { args.IsValid = true; }
else { args.IsValid = false; }
}

-------Server-Side:--------------
private void QuantityIncrementCheck(object sender, ServerValidateEventArgs
args)
{
try
{
int qtyIncrement = 0;//minimumQuantityIncrement;
int qty = int.Parse(args.Value);

args.IsValid = ((qty % qtyIncrement) == 0);
}
catch
{
args.IsValid = false;
}
}

Thanks in advance,
Aaron
 

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
474,085
Messages
2,570,597
Members
47,218
Latest member
GracieDebo

Latest Threads

Top