How to: Create a simple fly-out message in SP2010

I wanted to use a fly-out message to inform a user who was navigating from a configuration page to the homepage that his/her configuration had been saved successfully. To do so, I saved a custom variable in the Session object, and then retrieved the value after the redirection, displayed the message, and cleared the variable from the Session object, so that the fly-out wouldn’t be displayed every time he/she navigated to the homepage.

The following illustrates the above:

if (Session[Constants.SessionVariables.PERSONALISATION_REDIRECTION_DONE] != null && Session[Constants.SessionVariables.PERSONALISATION_REDIRECTION_DONE] != string.Empty)
{
StringBuilder stringBuilder = new StringBuilder();
stringBuilder.AppendLine(“<script>”);
//First wait until the SP.js is loaded, otherwise the Notification doesn’t work and we get an null reference exception
stringBuilder.AppendLine(“ExecuteOrDelayUntilScriptLoaded(Initialize, \”sp.js\”);”);
stringBuilder.AppendLine(“function Initialize() {“);
stringBuilder.AppendLine(“SP.UI.Notify.addNotification(\”” + Constants.Messages.PERSONALISATION_CONFIRMATION + “\”, false, \”Tip\”, null);”);
stringBuilder.AppendLine(“}”);
stringBuilder.AppendLine(“</script>”);
this.Controls.Add(new LiteralControl(stringBuilder.ToString()));
}

MGR: the Intelogist

About MGR: the Intelogist

SharePoint Server developer, turned Sitefinity developer, turned Angular developer, turned SharePoint Online consultant, turned Unily consultant, turned O365 consultant... Never a dull moment!

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes:

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong> 

This site uses Akismet to reduce spam. Learn how your comment data is processed.