SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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

share|improve this question
up vote 2 down vote accepted
    // your code here

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

share|improve this answer
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 '13 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 '13 at 18:11
Sounds possible, maybe you should have some kind of check before showing the modal – Robert Lindgren Oct 15 '13 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 '13 at 20:13

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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