Categories
discuss

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;
        }
        else
        {
            arguments.IsValid = false;
        }

        return arguments;
    }
</script>

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?

Answer

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.

Source: stackoverflow
Text is available under the Creative Commons Attribution-ShareAlike License; additional terms may apply. By using this site, you agree to the Privacy Policy, and Copyright Policy. Content is available under CC BY-SA 3.0 unless otherwise noted. The answers/resolutions are collected from stackoverflow, are licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0 © No Copyrights, All Questions are retrived from public domain..