2

So far I have tried this:

Page.ClientScript.RegisterStartupScript(this.GetType(), 
 "closePage", 
 "window.returnValue='http://sp-pubdev:88/Resources/Images/testFile.png';
 alert(window.returnValue);
 SP.UI.ModalDialog.commonModalDialogClose(SP.UI.DialogResult.OK);", true
);

and this:

Page.ClientScript.RegisterStartupScript(this.GetType(), 
 "closePage", 
 "window.returnValue='http://sp-pubdev:88/Resources/Images/testFile.png';
 alert(window.returnValue);
 window.close();", true
);

With both of these I will see my alter, but the window never closes. Is there something else I need to be doing here?

2 Answers 2

6

In code behind u close model popup like this

Response.Write("<script type='text/javascript'>window.frameElement.commitPopup();</script>");
                      Response.Flush();
                      Response.End();

I hope u use application page otherwise u not get Response object

0

I hope this helps:

  1. How to close show model dialog box in codebehind.

EDIT

I found this blog and goes into detail on closing a modal dialog!

SharePoint 2010: Closing a ModalDialog Manually from Code (C# and JavaScript).

3
  • Yeah they basically suggest the first method I was using. I tried adding the second parameter to see if that would make it work, but no dice. Aug 16, 2012 at 22:41
  • have you tried this: void btnOK_Click(object sender, EventArgs e) { this.Context.Response.Write("<script type='text/javascript'>window.frameElement.commitPopup();</script>"); this.Context.Response.End(); } social.technet.microsoft.com/Forums/en-US/…
    – Ali Jafer
    Aug 16, 2012 at 23:02
  • also this should work: SP.UI.ModalDialog.commonModalDialogClose(1, 'Submitted');
    – Ali Jafer
    Aug 16, 2012 at 23:05

Your Answer

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

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