SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I use in my web part a Session[""] and would like to notify the user when the session is expired. I check at the PostBack event if the session is already okay, if not, I will execute a JS function which shows the SP.UI.Status warning message.

Now I don’t know how I could execute the JS. I tested it the ScriptManager, but then I get a error, that the SP.UI.Status is not define. How could I add the SP.UI.Status at the PostBack?


The same issue occurs with SP.UI.Notify and is fixed with the same solution.

share|improve this question
up vote 9 down vote accepted

My guess for the reason you are having trouble with calling SP.UI.Status.addStatus is because the SP.js script file (which contains the namespace and relevant functions) is loaded on demand.

In order to call SP.UI.Status.addStatus() as soon as the page loads, you'll need to make sure you use the script on demand framework for doing so.

Something like this

ExecuteOrDelayUntilScriptLoaded(mysessionexpiredfunction, 'sp.js')

share|improve this answer
That exactly what I mean! I didn’t know anything about the ExecuteOrDelayUntilScriptLoaded() method. I could solved it with: this.Page.ClientScript.RegisterStartupScript(this.GetType(), "test", "ExecuteOrDelayUntilScriptLoaded(test, 'sp.js');", true);. Thanks!!! – hofmeister Nov 22 '11 at 13:51

The easiest solution would be to check if the session has expired client side onclick(). Then it's merely a function call to the SP.UI.Status.addStatus()

If that's not possible, there are some alternatives I've used with various success in the past. You could e.g. try to use Response.Write("<script language='javascript'>SP.UI.Status.addStatus();</script>"); like shown here.

share|improve this answer
Mhm how should that work? Output is not a method. I tried it with ScriptManager.RegisterStartupScript(Page, Page.GetType(), "test", "test();", true); but here i get following error: Microsoft JScript runtime error: Unable to get value of the property 'addStatus': object is null or undefined. I think at that point, the SP.UI.Status.addStatus is not ready, right? If I executed the function with a test button everything works fine. – hofmeister Nov 22 '11 at 13:24
Yeah, you're right. If you have to do it serverside, Paul Lucas' method is better. – tarjeieo Nov 22 '11 at 14:00

When function with parameters view:

Pass parameters in ExecuteOrDelayuntilScriptLoaded in Javascript client Object model

You can use an function as a delegate and then call your function with in.

ExecuteOrDelayUntilScriptLoaded(function () { alertThis("Hello World") }, "core.js");

function alertThis(value)
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.