javascript - ASP.Net Custom Client

original title: "javascript - ASP.Net Custom Client-Side Validation"


I have a custom validation function in JavaScript in a user control on a .Net 2.0 web site which checks to see that the fee paid is not in excess of the fee amount due.

I've placed the validator code in the ascx file, and I have also tried using Page.ClientScript.RegisterClientScriptBlock() and in both cases the validation fires, but cannot find the JavaScript function.

The output in Firefox's error console is "feeAmountCheck is not defined". Here is the function (this was taken directly from firefox->view source)

<script type="text/javascript">
    function feeAmountCheck(source, arguments)
        var amountDue = document.getElementById('ctl00_footerContentHolder_Fees1_FeeDue');
        var amountPaid = document.getElementById('ctl00_footerContentHolder_Fees1_FeePaid');

        if (amountDue.value > 0 && amountDue >= amountPaid)
            arguments.IsValid = true;
            arguments.IsValid = false;

        return arguments;

Any ideas as to why the function isn't being found? How can I remedy this without having to add the function to my master page or consuming page?

Van egy egyéni érvényesítési funkcióm a JavaScript alkalmazásban a .Net 2.0 webhely felhasználói vezérlőjén, amely ellenőrzi, hogy a fizetett díj nem haladja-e meg a fizetendő díjat. Helyeztem az érvényesítőt ...

Ez az összefoglalás a fordítás után. Ha meg szeretné tekinteni a teljes fordítást, kattintson a "fordítás" ikonra

Minden válasz
  • Translate

    Try changing the argument names to sender and args. And, after you have it working, switch the call over to ScriptManager.RegisterClientScriptBlock, regardless of AJAX use.

  • Translate

    When you're using .Net 2.0 and Ajax - you should use:


    It will work better in Ajax environments then the old Page.ClientScript version

  • Translate

    Also you could use:

    var amountDue = document.getElementById('<%=YourControlName.ClientID%>');

    That will automatically resolve the client id for the element without you having to figure out that it's called 'ctl00_footerContentHolder_Fees1_FeeDue'.

  • Translate

    While I would still like an answer to why my javascript wasn't being recognized, the solution I found in the meantime (and should have done in the first place) is to use an Asp:CompareValidator instead of an Asp:CustomValidator.