When I saw the notifications in 2010 for the first time, I really thought that could be used for some very cool stuff. For example, wouldn’t it be cool to set up a message somewhere centrally like “Servers are going down this weekend for maintenance” and everybody sees that notification in their browser.
Well, I managed to get such a nice little app working (you wouldn’t have thought that eh? ;) So what did was the following:
- Create a control that displays the message based on the centrally managed setting
- Create an application page where you can set the message and other properties.
- Make use of the AdditionalPageHead delegate to load the control on every page
Below are some screenies how it looks:

I had some problems to display the notification on the load of the page, since it was working on postbacks. There was something going on with the order of loading of the several javascripts. While debugging the page using the IE Developer Toolbar it seemed that only two classes of the SP.UI namespace were loaded (and thus not the Notify one). So I had to figure a way on how to make my control display the notification after the SP.js was loaded. Luckily my buddy Waldek had came across such a problem before and told me to make use of the following JavaScript function “ExecuteOrDelayUntilScriptLoaded(‘functionToExecuteAfterScriptIsLoaded’, ‘javascriptFileToLoad’)”, and that the trick! :)
Here is the source of the UserControl where I add javascript to the page that loads the Notification:
protected override void CreateChildControls()
{
SPWebApplication webApplication = SPContext.Current.Site.WebApplication;
Notification notification = webApplication.GetChild<Notification>("Notify");
if (notification.Display)
{
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(\"" + notification.Message + "\", " + notification.Sticky.ToString().ToLower() + ", \"Tip\", null);");
stringBuilder.AppendLine("}");
stringBuilder.AppendLine("</script>");
this.Controls.Add(new LiteralControl(stringBuilder.ToString()));
}
base.CreateChildControls();
}
Pretty neat eh? I’m not really a big fan of adding a script like I just did but at least it get’s the job done… the complete solution is on CodePlex, so if you’re interested to take a look at it be my guest!
For the next release/update I want to work on :
- Asynchronous updates
- Make use of the status bar as well so you can choose to use the Status Bar of the Notifications
- Make a ribbon action and add that to the WebApplication Ribbon and use a popup for the Settings.aspx
Posts that helped me out (thanks guys!) :
@Zimmergren : this was the cliff hanger I was tweeting about ;)