CustomValidator server-side

Discussion in 'ASP .Net Web Controls' started by Next, Jan 6, 2004.

  1. Next

    Next Guest

    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
     
    Next, Jan 6, 2004
    #1
    1. Advertising

  2. Next

    Next Guest

    Changed the method from private to protected and fixed the problem.
     
    Next, Jan 6, 2004
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. John Bonds

    CustomValidator client-side scripting

    John Bonds, Aug 23, 2004, in forum: ASP .Net
    Replies:
    0
    Views:
    4,244
    John Bonds
    Aug 23, 2004
  2. Mo
    Replies:
    3
    Views:
    2,185
    Mo hariri
    Jan 15, 2005
  3. Mythran
    Replies:
    2
    Views:
    515
    Mythran
    Jan 22, 2005
  4. peshrad
    Replies:
    1
    Views:
    295
    peshrad
    Jul 22, 2004
  5. Mo

    Server side CustomValidator and FormView

    Mo, Mar 2, 2005, in forum: ASP .Net Web Controls
    Replies:
    0
    Views:
    145
Loading...

Share This Page