In this article, I’ll explain a way to handle page navigation from code behind using Literal control in Sandboxed solution.
There are some restrictions in using Page.Response.Redirect to navigate pages in SharePoint sandboxed solutions. If you want to handle page navigation from Code behind, you can make use of the literal control that invokes the script for page navigation.
Here is how it works
Step 1
In the SharePoint sandboxed web part add a Literal control and name it as your wish like the one shown below:
<asp:Literal ID="litRedirect" runat="server" />
Step 2
Now on your web part’s code behind, you can assign the script as text of the literal control. Here is the code segment that assigns the script as text to Literal control:
string redirectURL = string.Format("{0}/{1}", SPContext.Current.Web.Url, "SitePages/PageName.aspx");
litRedirect.Text = "<script type='text/javascript'>window.location = '" + redirectURL + "/';</script>";
That’s all, you’re done. As soon as you assign the script to literal control in your code behind, you will be navigated to the page that you specified.
Summary
In this article we have seen a way to handle page navigation in SharePoint sandboxed solution. Stay tuned for more articles.
For more articles Visit: SharePoint Contriver