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

  • Where do you call this code from? – MdMazzotti Jan 16 '14 at 12:58
  • i calling this code from server side of modal popup page – Hitesh Chandegara Jan 16 '14 at 13:05
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);
| improve this answer | |
0

Try this

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

It always works for me.

| improve this answer | |
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.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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