Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

I'm trying to add a UI notification from server side. To do this, I've written this code in one of my code behind event handler:

    private void AddNotifySuccessScript()
        var scriptTemplate = "ExecuteOrDelayUntilScriptLoaded(function(){{ SP.UI.Notify.addNotification(\"{0}\",true); }}, 'sp.js');";
        var script = string.Format(
            "Message".Replace("\"", "\\\"") // TODO: message in parameters
        Page.ClientScript.RegisterStartupScript(typeof(MyControl), "notifysuccess", script, true);

This is resulting in this JS code produced in the page :

ExecuteOrDelayUntilScriptLoaded(function(){ SP.UI.Notify.addNotification("Message",true); }, 'sp.js');

Which is, I believe, expected.

However, when I execute the page, I got a client side error:

SCRIPT5007: The value of the property 'addNotification' is null or undefined, not a Function object

Especially, the code breaks in this SharePoint code (the addNotification method is undefined at this point) :

SP.UI.Notify.addNotification = function(strHtml, bSticky) {ULS5Vl:;
    return addNotification(strHtml, bSticky);

But if I let the page reach the end, I can see that the addNotification is eventually available.

How can I fix this? It looks like that for some reason, my function is fired before the actual load of the sp.js file.

share|improve this question
Which version of SharePoint did you do this on? I think the confusion is that SP.UI.Notify is defined in sp.js in 2010 and core.js in 2013 - most examples will show code for 2010 but guessing you were using 2013 and needed to reference core.js instead. –  Ryan Dec 1 at 22:15

3 Answers 3

up vote 3 down vote accepted

I finally find a way to solve my issue. Here is the modified script :

    private void AddNotifySuccessScript()
        var scriptTemplate = @"
        var script = string.Format(
            "Message".Replace("\"", "\\\"")
        Page.ClientScript.RegisterClientScriptBlock(typeof(GenericFormWebPartUserControl), "notifysuccess", script, true);

With the help of Andrey Markeev, I find that the addnotification depends on two script files. Here I nest my on demand load of these script to be sure both are loaded.

I didn't succeed in using the "inplview" dependency though.

share|improve this answer
You don't need to reference both core.js and sp.js - it depends upon which version of SharePoint you're using - see my answer below. –  Ryan Dec 1 at 22:21

addNotification function resides in core.js file, while SP.UI.Notify.addNotification is found in sp.js. As you probably know, all those SharePoint javascript files are registered on page and loaded there via Script-On-Demand (SP.SOD) system.

Obviously these files have dependencies, and my investigation shows (see the screenshot below) that sp.js is not marked as dependent from core.js for some reason:

enter image description here

Thus to solve this issue, you can use some script which is dependent from both sp.js and core.js. For example, it can be "inplview" (notice, no ".js" at the end!):

enter image description here

Thus I propose you to try the following code:

    var scriptTemplate = "ExecuteOrDelayUntilScriptLoaded(function(){{ SP.UI.Notify.addNotification(\"{0}\",true); }}, 'inplview');";

P.S. I never experienced this behavior, although I use SP.UI.Notify very often. And I always use "sp.js" for ExecuteOrDelayUntilScriptLoaded. I assume the cause of the problem you're facing is that you use "RegisterStartupScript", and somehow sp.js appears in the load queue before the "core.js" file.

share|improve this answer
I've tried this : RegisterSod('test','oneofmyutils.js'); RegisterSodDep('test','core.js'); RegisterSodDep('test','sp.js'); ExecuteOrDelayUntilScriptLoaded(function(){ debugger;SP.UI.Notify.addNotification("Message",true); }, 'test'); But this does not fire the method :'( –  Steve B Mar 4 '13 at 9:27
Did you also try the variant I suggested in the answer? With inplview? Inplview is OOTB script. –  Andrey Markeev Mar 4 '13 at 12:30
this does not works. But I find a solution, look at my own answer –  Steve B Mar 4 '13 at 13:45
This does work for me (on 2010/13) BUT only if you use ExecuteOrDelayUntilScriptLoaded("yourfunc","inplview.js") not just "inplview" –  Ryan Dec 1 at 22:13
Also not sure if using inplview.js is a good idea if you don't actually need anything in it. Should be able to fix this by referencing either core.js or sp.js depending on sp version (see my comment in orig. question) –  Ryan Dec 1 at 22:17

I've found that it SP.UI.Notify is defined in different places depending on which version of SharePoint you've got.

2010 - is sp.js so


2013 - is core.js so

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.