<p>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. </p>

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

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

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

        if (amountDue.value &gt; 0 &amp;&amp; amountDue &gt;= amountPaid)
        {
            arguments.IsValid = true;
        }
        else
        {
            arguments.IsValid = false;
        }

        return arguments;
    }
&lt;/script&gt;
</code></pre>

<p>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?</p>

[{'answer_id': 1405, 'author': 'brendan', 'author_id': 225, 'author_profile': 'https://Stackoverflow.com/users/225', 'pm_score': 3, 'selected': False, 'text': "<p>When you're using .Net 2.0 and Ajax - you should use:</p>\n\n<pre><code>ScriptManager.RegisterClientScriptBlock\n</code></pre>\n\n<p>It will work better in Ajax environments then the old Page.ClientScript version</p>\n"}, {'answer_id': 1418, 'author': 'Greg Hurlman', 'author_id': 35, 'author_profile': 'https://Stackoverflow.com/users/35', 'pm_score': 5, 'selected': True, 'text': '<p>Try changing the argument names to <code>sender</code> and <code>args</code>.  And, after you have it working, switch the call over to <code>ScriptManager.RegisterClientScriptBlock</code>, regardless of AJAX use.</p>\n'}, {'answer_id': 1527, 'author': 'Rob Allen', 'author_id': 149, 'author_profile': 'https://Stackoverflow.com/users/149', 'pm_score': 0, 'selected': False, 'text': "<p>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 <code>Asp:CompareValidator</code> instead of an <code>Asp:CustomValidator</code>.</p>\n"}, {'answer_id': 991196, 'author': 'kpax', 'author_id': 75314, 'author_profile': 'https://Stackoverflow.com/users/75314', 'pm_score': 0, 'selected': False, 'text': "<p>Also you could use:</p>\n\n<pre><code>var amountDue = document.getElementById('&lt;%=YourControlName.ClientID%&gt;');\n</code></pre>\n\n<p>That will automatically resolve the client id for the element without you having to figure out that it's called <code>'ctl00_footerContentHolder_Fees1_FeeDue'</code>.</p>\n"}]
['https://Stackoverflow.com/questions/1401', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/149/']