c# - Calling jQuery function on Master Page body onload: 0x800a1391 - JavaScript runtime error: function is undefined -


i have master page includes following script:

<!doctype html public "-//w3c//dtd xhtml 1.0 strict//en" "http://www.w3.org/tr/xhtml1/dtd/xhtml1-strict.dtd">  <html xmlns="http://www.w3.org/1999/xhtml">  <head runat="server">  	<title><asp:contentplaceholder id="titlecontent" runat="server" /></title>  	  	<script src="<%=url.content("~/scripts/jquery-1.4.4.min.js") %>" type="text/javascript"></script>      	<script src="<%=url.content("~/scripts/jquery-ui-1.8.7.custom.min.js") %>" type="text/javascript"></script>      	<link href="<%=url.content("~/content/site.css") %>" type="text/css" rel="stylesheet" />    	<link href="<%=url.content("~/content/jquery-ui/pepper-grinder/jquery-ui-1.8.7.custom.css") %>" type="text/css" rel="stylesheet" />      	<script src="<%=url.content("~/scripts/microsoftajax.js") %>" type="text/javascript"></script>  	<script src="<%=url.content("~/scripts/microsoftmvcajax.js") %>" type="text/javascript"></script>  	<script src="<%=url.content("~/scripts/microsoftmvcvalidation.js") %>" type="text/javascript"></script>    	<% if ( false ) { %>  			<script src="<%=url.content("~/scripts/jquery-1.4.1-vsdoc.js") %>" type="text/javascript"></script>      	<% } %>      	<script type="text/javascript">  	    $(document).ready(function () {    	        $(function hidemessage() {  	            $('.sessionmessage').delay(5000).fadeout(2000);  	        })      			$('[id $=link]').click(function () {  				var txt = $(this).attr("id").substr(0, $(this).attr("id").length - 4);  				$.ajax({  					url: this.href,  					cache: false,  					success: function (result) {  						$('[id ^=' + txt + '][id $=table]').append($(result));  					},  					error: function (xhr, err) {  						alert("readystate: " + xhr.readystate + "\nstatus: " + xhr.status + "\nresponsetext: " + xhr.responsetext);  					}  				});  				return false;  			});  		});  	</script>

in same master page, on body tag, call hidemessage function:

<body onload="hidemessage();">

when debug application, following message:

0x800a1391 - javascript runtime error: 'hidemessage' undefined

i've been trying every permutation of script location , nothing seems affect validity of tiny little script. other scripts seem loading fine, , application runs (at least initially).

if calling function <body onload='fn_name()' create func outside document.ready()

<head>     <script>       function hidemessage(){         alert("hello world");       }     </script>     </head>     <body onload="hidemessage();">     hello world ...     </body> 

or

instead of calling <body onload='fn_name()' direct call in ready function mentioned in 1st comment .i.e

<script>    $(document).ready(function(){        helloworld(); // when dom ready function gets call        function helloworld(){           alert("helloworld");               } });  </script> <body> hello world  </body> 

Comments

Popular posts from this blog

Java 3D LWJGL collision -

spring - SubProtocolWebSocketHandler - No handlers -

methods - python can't use function in submodule -