Notifications not showing when displayed in dialogs

I love working with the new dialog framework and notifications in SharePoint 2010. The other day though I ran into an issue with the notifications that somehow wouldn’t show up when I tried to use them in an application page I’ve built that was displayed through the dialog framework.

In my application page I wanted to use display a notification to the user. My code looked something like this:  

        var notifier = {
            _nid: null,
            ShowMessage: function (msg) {
                notifier._nid = SP.UI.Notify.addNotification("This is a message...", true);
            HideMessage: function () {
                notifier._nid = null;


And for the purpose of this post let’s use two buttons, one to show the notification and one to hide it:

    <input type="button" 
        value="Show Notification" 
        style="width:150px" />
    <input type="button" 
        value="Remove Notification" 
        style="width:150px" />

Opening the page in the browser (not through a dialog) and clicking the “show” button displays this:


…as expected.


But what happens if I open this application page in a dialog?


To “simulate” that behavior I added the IsDlg=1 query string parameter which is what the dialog framework will do for us if we where to open this page in a dialog. 

The first thing to notice is that the ribbon disappears completely from the page and secondly when I click the button again nothing happens.



So why is this happening?

I searched the internet to find an answer for this and yes I did find a solution for the problem (which is at the end of this post) but I always like to know why this happens and not only how to solve it. So my investigation starts…


If I use firebug to inspect the html I can see that the ribbon (the div in the screenshot that is highlighted) is in fact rendered on the page but a style rule is hiding it. That style rule resides in some style sheet called dlgframe.css which I’ve tried to illustrate above.

Using firebug I tried to remove that line (display:none) and the ribbon row appeared again and the notification was displayed like before. You can see it from the image below that the page now has that dark blue ribbon row.



How do the notifications work?

In order to fully understand the problem I now looked at the JavaScript used to display the notifications. 


Deep inside the core.js file I found that the notifications are finally shown using an element with id notificationArea.
That element resides inside the ribbon (which you an see from the screenshot above). So if that element isn’t visible the notifications simply will not be shown to the user.


The dlgframe.css style sheet

Going forward in my investigation I found that the dlgframe.css style sheet has been added to the head tag of the page (hmmm who did that?)


If we have a look inside that style sheet one of the rules read:


Or in plain English if you don´t speak fluent CSS:
”set display equals none to the element with id s4-ribbonrow that is a child of a body tag and if that body tag is also a child of an element with a class name that reads ms-dialog-nr 

OK, so we know that s4-ribbonrow is that div that is the starting point of the Ribbon from what we saw earlier. That div is a child of the body tag (duh?).
Furthermore, if we inspect the html that is outputted when IsDlg=1 is added to the query strings, the html tag apparently has a class named ms-dialog-nr…hey that is what that style rule says!!


That is exactly what we saw earlier in firebug and that is the rule that hides the ribbon and ultimately what causes the problem with the notification to being hidden. OK, so now that we know why the notification won´t display we’ll now continue with the how is that possible?

Which control outputs these style rules then?

It turns out that the CssLink control is the culprit. From the OnLoad method a call is made to the SeupDialogCSS method that looks like this:


Looking at the code with ILSpy you can see that if the current SPContext is a dialog (e.g. IsDlg=1) the dlgframe.css is registered (among some other thing that I have omitted for now). 

The CssLink control is added to the html via the applicationv4.master that the application page uses (if we haven´t overridden that with a custom one…chances that it uses the CssLink are still there though).  


So what options does this present us with?

One option is to use JQuery to forcefully show the ribbon row, something like:


Somehow, that doesn’t seem quite right though.


Another option


That is a screenshot of some more code from the CssLink class that I omitted before.
From it we can see that the code uses the SPRibbon to determine if the command UI is not set to show (by default) and if so the ms-dialog-nr css class is added to some HtmlGenericControl which is in fact the html tag (that can bee seen from looking at the whole code).

This presents us with an option though.
Change that behavior in the code behind used by our application page, thus forcing the CssLink not adding that css class.

        protected override void OnPreRender(EventArgs e)
            if (SPContext.Current != null && SPContext.Current.IsPopUI)
                var ribbon = SPRibbon.GetCurrent(this.Page);
                if (ribbon != null)
                    ribbon.CommandUIVisible = true;

Build, Deploy and…




…it’s showing!!!


, , ,

  1. #1 by Arthur J. on August 26, 2011 - 17:24

    Thanks! I’ve spent whole day to find out why this notifications are not displayed in my dialog window. Then after some googling I found your site! Thank you one more time.

    • #2 by Johan Leino on August 26, 2011 - 22:02

      Yeah, I spent some time looking into it also so I thought the next person shouldn’t have to. Thanks!!

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: