Im trying to open a dialog with the following code :

    var options = {
                    url: "www.hotmail.com",
                    width: 550,
                    height: 200 
    SP.SOD.execute('sp.ui.dialog.js', 'SP.UI.ModalDialog.showModalDialog', options);

this code is found in the .ascx of a visual webpart that i need to create. But when i click on the button that should call the following function from the backend with the following code :

Page.ClientScript.RegisterStartupScript(GetType(), "msgbox", " printModal();", true);

did the same procedure in an application page and it worked without an issue but when doing it inside a webpart its never working. Can anybody enlighten me where the problem lies?

  • If you open up your browser's dev tools, then view the console, are you getting any JavaScript errors? Commented Sep 4, 2014 at 14:27
  • yes "printModal is not defined" Commented Sep 4, 2014 at 14:28

1 Answer 1


That means the RegisterStartupScript block is executing before your printModal function is defined. It was probably working in the application page because the function was defined before the script was getting called.

You can fix this by just declaring your printModal function in the code-behind, using something like RegisterClientScriptBlock before calling it.

Here are some examples:



Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.