Manjuboyz Manjuboyz - 1 year ago 145
ASP.NET (C#) Question

onclick event is not working when function is in external javascript file

Before coming here I tried few links listed in stackoverflow, but none of them helped me to get this issue fixed Or may be I am doing something wrong.

I have a input button in my aspx and have serverclick event as well as onclick, both client and server methods are called correctly, I only facing problem when the 'onclick' function is in external file(it is in same directory).

I even referenced the js file in aspx.


all other controls are working in external js except this.

inline function works fine, but not when moved in external function.

I even tried window.onload() but it triggers the function during pageload which is not what I need.


<script type="text/javascript" src="external.js"></script>

Input button.

<input class="data" type="submit" name="cmdSubmit" value="Run Report" onclick="return FormValidate();"
onserverclick="RunReport" runat="server" id="Submit1" />


$(document).ready(function () {
function FormValidate() {

Answer Source

Please remove $(document).ready(function () { present around your function FormValidate() to make it global function. Right now by placing it inside ready handler you are making it a local scoped function. So your external.js should be:

function FormValidate() {
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download