I have created an application page that mimics an input form. This form will eventually go into an SP List with other forms. What I'm after is when a user clicks the link to the form from the SP List, it will open the application page in a modal dialog.

I have used Modal Dialogs in SharePoint before, but that is always after some user event such as a button click or hyperlink navigation, but never on page load.

I have tried using JS with: window.onload = function() { SP.UI.ModalDialog.ShowPopupDialog(myURL); } but that didn't work.

I also tried Registering the script on start up in code-behind, but that does nothing as well.

Any help will greatly be appreciated. Thanks

1 Answer 1

    // your code here

This will make sure your method is not trying to execute before the SP javascrips are loaded

  • That did the trick! Only now when the modal dialog loads, it keeps loading in an infinite loop. Not sure if a callback is needed or if there's a flag to stop call after SP scripts are loaded.
    – J-man
    Oct 15, 2013 at 18:03
  • Not sure, but is probably because in the options for my SP.UI.ModalDialog.showModalDialog, the url is the application page this code is on, so if it opens it again, then naturally the JS will execute again and again and again because it's opening the same application page again and again and again.
    – J-man
    Oct 15, 2013 at 18:11
  • Sounds possible, maybe you should have some kind of check before showing the modal Oct 15, 2013 at 19:33
  • Yeah, I was thinking either that or have a dummy page to call the modal javascript to open the "real" aspx page where my content resides. Sounds kind of gimmicky, but I'm still looking for other options. Again, thanks for your help on this, I really appreciate it.
    – J-man
    Oct 15, 2013 at 20:13

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.