0

i tried to close the modal dialog in sandbox solution using the following code

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

but its throwing null value error at

context.Response.End();

this works fine in farm solutions but not work sandbox solution.

is there any way to close modal dialog in sandbox solutions?

Thanks in advance

2
  • Where do you call this code from?
    – MdMazzotti
    Jan 16, 2014 at 12:58
  • i calling this code from server side of modal popup page Jan 16, 2014 at 13:05

3 Answers 3

2

Try with the following code,

Page.ClientScript.RegistrerClientScriptBlock(this.getType(), "script", "SP.UI.ModalDialog.commonModalDialogClose(1, someValue");

Or use a script manager in your page and try with the following code,

ScriptManager.RegisterClientScriptBlock(Page, Page.GetType(), Guid.NewGuid().ToString(), "
<script type="text/javascript" language="javascript">                SP.UI.ModalDialog.commonModalDialogClose(1, 'Submitted');     </script>", true);
1
0

Try this

this.Response.Write("<script language=\"javascript\">window.parent.close();</script>");
this.Response.Flush();

It always works for me.

1
0

The reason why your redirect code isn't working and it raises Null Exception may be because your WebPart is a Sandboxed solution.

For redirect in SandBoxed solutions you can try the following:

  1. Create a Literal control.

  2. In your code-behind, add similar code as this one:

    literalRedirect.Text = "<script type='text/javascript'>window.location.replace('" + redirectUrl + "');</script>"; //where /(redirectUrl) is a String variable.
    

Source: here.

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.