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 status bar to show exception message in code-behind. I wanna add a close button in the status bar for user, so they can remove the bar. Here is my code:

        protected virtual void ShowNotifyException(Severity severity, string errorMessage)
        string statusBar = @"
                    this.statusID = SP.UI.Status.addStatus(""{0}"", ""<p><span style='float: left'>{1}</span><span style='float: right'><input type='button' name='cancelStatusBar' value='X' onclick='SP.UI.Status.removeStatus(this.statusID);'/></span></p>"");
                    SP.UI.Status.setStatusPriColor(this.statusID, ""{2}"");

        string color = "";
        string title = "";
        if (severity.Equals(Severity.Error))
            color = "red";
            title = EMC.Documentum.SharePoint.Core.ResourceManagement.ResourceManager.GetLocalString("StatusBarTitle_Error");
        else if (severity.Equals(Severity.Warn))
            color = "yellow";
            title = EMC.Documentum.SharePoint.Core.ResourceManagement.ResourceManager.GetLocalString("StatusBarTitle_Warn");
        else if (severity.Equals(Severity.Info))
            color = "blue";
            title = EMC.Documentum.SharePoint.Core.ResourceManagement.ResourceManager.GetLocalString("StatusBarTitle_Info");
            color = "green";
        string script = string.Format(statusBar, title, errorMessage, color);
        ScriptManager.RegisterClientScriptBlock(Page, GetType(), "ShowErrorMessage", script, true);

The question is, 1. the button is displayed correctly, but it doesn't work. 2. Except add button, is there any other way to implement my requirement?

share|improve this question
I don't wanna add timeout for the status bar, because our requirement is to remove status bar from a button. – ChrisLiu May 24 '13 at 12:03
up vote 2 down vote accepted

I separate the JS to a standalone file, and include a function:

var statusID='';
var addStatusBar = function(title, message, color){
var messageHtml = '<p><span style="float: left"><b>' + title + '</b>' + message + '</span><span style="float: right" id="close_button_span"></span></p>';
statusID = SP.UI.Status.addStatus(messageHtml);
SP.UI.Status.setStatusPriColor(statusID, color);
var close_button = document.createElement('a');
var linkText = document.createTextNode("close");
close_button.appendChild(linkText); = 'status_close_button';
close_button.href = "#";
close_button.onclick = function(){
    statusID = '';
var statusBar = document.getElementById('close_button_span');

Then register the js file in CreateChildControls with ScriptLink control, and use below statement to call the js function:

ScriptManager.RegisterClientScriptBlock(Page, GetType(), "ShowErrorMessage", "ExecuteOrDelayUntilScriptLoaded(function() {{addStatusBar('Error: ', 'message', 'red')}}, 'sp.js');", true);

The button in status bar will be worked.

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.