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()));
}