I have below JavaScript function in my aspx page:
<script>
function ShowMessage() {
alert("Hello World");
}
</script>
I want to use this function in my cs page on button click event:
<asp:Button ID="MyButton" runat="server" Text="Click Here" OnClick="MyButton_Click" />
Now this code works fine:
Page.ClientScript.RegisterStartupScript(this.GetType(), "myScript", "alert('Hello World');", true);
But this code dose not work:
Page.ClientScript.RegisterStartupScript(this.GetType(), "myScript", "ShowMessage();", true);
What's wrong in my code? What's the possible reason?