Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

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
add comment

1 Answer 1

up vote 1 down vote accepted
ExecuteOrDelayUntilScripLoaded(function(){
    // your code here
    },"sp.js");

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. –  user2063134 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. –  user2063134 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. –  user2063134 Oct 15 '13 at 20:13
add comment

Your Answer

 
discard

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.