Skip to content
Amal Hashim
All posts
Snippet

SharePoint Sandbox Solution - Page Redirect

A sandbox solution cannot call Response.Redirect, so write a small script through a literal control instead.

1 min read#C##SharePoint#SharePoint 2010

Redirecting to another page from a sandbox solution is awkward, because the usual server side redirect is not available. A workaround is to let the web part write a client side redirect.

Add a literal control to the web part:

html
<asp:Literal ID="litRedirect" runat="server" />

Then, from the code behind, set its text to a script that changes the window location:

csharp
litRedirect.Text = "<script type='text/javascript'>window.location = 'https://example.com/';</script>";

Scenario

  1. A sandbox web part saves a form.
  2. After the save succeeds, the code behind sets litRedirect.Text.
  3. The browser runs the script and moves to the thank you page.