Pages

Tuesday, January 27, 2015

How to redirect from one page to another in SharePoint Sandbox solutions (especially when they are deployed to SharePoint Online)



How to redirect from one page to another in SharePoint Sandbox solutions (especially when they are deployed to SharePoint Online)?



Answer -


There are lots of ways to achieve this but the following one works almost everywhere for the sandbox solutions.

On a button click event (or accordingly) of your ".cs" file, just add following code:


string pageURL = "www.yourpageurl.com";
var jscript = "<script type='text/javascript'
language='javascript'>window.location='"
+ pageURL + "';</script>";
var literal = new Literal();
literal.Text = jscript;
this.Controls.Add(literal);


The above code will add "Literal" control to page with the specified URL and the page will be redirected to the URL specified.

What is Literal Control?

- The Literal Control is similar to the Label Control as they both are used to display static text on a web page.
- The Literal Control is not inherited from WebControl namespace.
- The Literal Control doesn't provide substantial functionality but Literal text is programmable.
- It doesn't add any HTML elements to the web page. This control makes it possible to add HTML code directly in the code designer window without switching to design view and clicking the HTML button to edit the HTML.
- We cannot apply a style to a literal control.
- Unlike Label control, there is no property like BackColor, ForeColor, BorderColor, BorderStyle, BorderWidth, Height etc. for Literal control.

That makes it more powerful, we can even put a pure HTML contents into it.

When to use Literal Control?
- Literal control is one of the rarely used controls but it is very useful.
Literal control is light weight control.
- The Literal Control is useful when we want to add text to the output of the page dynamically (from the server).
- With that we can even programmatically manipulate the Literal text from the code behind.

In short we can say:

The Literal control is used to display text; that is, it renders static text on a Web page without adding additional HTML tags. It passes content directly to the client browser unless we use the Mode property to encode the content.
 

No comments:

Post a Comment