Reputation:
I have a JavaScript function in aspx page and this aspx page had several ascx control in it.
I need to call that JavaScript function from one of its ascx control code behind file. I tried below approach but it is not working as expected. Any suggestion please.
in aspx page:
<script type="text/javascript">
function Disable()
{
// some code
// return;
}
in ascx code behind file:
ScriptManager.RegisterClientScriptBlock(Me.Page, Me.GetType(), "Script", "Disable();", True)
Can someone please let me know how to resolve this?
Upvotes: 0
Views: 816
Reputation: 35564
Try RegisterStartupScript
instead of RegisterClientScriptBlock
ScriptManager.RegisterStartupScript(Page, GetType(), "Script", "Disable();", true);
RegisterClientScriptBlock writes the javascript content at the top of the HTML page content while RegisterStartupScript writes the content at the bottom. Chances are that your inline function 'Disable()` is below the code calling it, thus it does not found when fired.
Upvotes: 1