Click here to Skip to main content
15,905,679 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
In the code-behind:
C#
Page.ClientScript.RegisterStartupScript(
   GetType(),
   "MyKey",
   "myFunction();",
   true);

and in the .aspx:
JavaScript
<script type="text/javascript">
  function myFunction() {
    debugger;
  }
</script>
But I got JavaScript runtime error: 'myFunction' is undefined.  What's wrong in my code?  Thanks.


What I have tried:

JavaScript runtime error: 'myFunction' is undefined
Posted
Updated 13-Jul-16 9:29am
Comments
Karthik_Mahalingam 13-Jul-16 15:25pm    
your code works fine..
are you calling the code on page load ?

1 solution

try this
C#
ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "MyKey", "myFunction();", true);
 
Share this answer
 
Comments
s yu 13-Jul-16 15:33pm    
Tried but still got the same error.
Karthik_Mahalingam 13-Jul-16 15:55pm    
place this code inside head tag

<head>
<script type="text/javascript">
function myFunction() {
alert('test');
}
</script>
</head>

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900