0

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?

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.