How to use Status Bar in SharePoint 2010?
In SharePoint 2010, Status bar is used to display information/warnings without disturbing user with Javascript alerts. Please don't think it is Browser's Status bar. It's a special information bar which displays below ribbon/top bar when invoked. No Server side code or manual setup required to enable status bar. The required functions are bundled in SP.UI.Status class that defined in SP.Js/SP.Debug.Js and it's included in SharePoint master page. So no need to include Js manualy to use Status bar.
Well, Javascripts alerts are not helpful to display HTML content, images, links. Where Status bar accepts HTML content and can be invoked just with Javascript.
SP.UI.Status Functions
The SP.UI.Status class has 6 functions. They are
Well, Javascripts alerts are not helpful to display HTML content, images, links. Where Status bar accepts HTML content and can be invoked just with Javascript.
SP.UI.Status Functions
The SP.UI.Status class has 6 functions. They are
- SP.UI.Status.addStatus(strMessageHeading, strHTMLContent, boolAtBegining) This function used to display specified content in Status bar. The parameters are self explanatory. boolAtBegining parameter specifies whether this content should be shown at First(just like to give priority) and it's useful when more than one status messages invoked.
- SP.UI.Status.appendStatus(strStatusID, strHTMLContent) This function appends HTML content with an existing status bar content.
- SP.UI.Status.updateStatus(strStatusID, strHTMLContent) This function updates/replaces existing HTML content with given HTML content.
- SP.UI.Status.setStatusPriColor(strStatusID, strColor) This function sets/changes the color of status bar. Only four colors[red, yellow, green, blue] are allowed which specifies the priority. Red - High Priority, yellow, green, blue - Low Priority. When two colors applied on same status bar then High priority color will be considered by SharePoint.
- SP.UI.Status.removeStatus(strStatusID) This function removes the specific Status bar.
- SP.UI.Status.removeAllStatus(boolHideStatus) This function removes all Messages. If the boolHideStatus passed as true then it'll hide all status bar with messages. Otherwise it'll hide only Status Message but a thin status bar will remains in place.
How to add code?
Follow the steps to add Content Editor Webpart and add HTML/Javascript Code.
Follow the steps to add Content Editor Webpart and add HTML/Javascript Code.
- Site Actions -> Edit Page (or Edit page Icon on top bar)
- Click Editing Tools(Tab) -> Insert (Tab) -> Webpart
- Select Media and Content (Section) -> Content Editor.
- Select Content Editor Webpart (Black triangle on top right of the webpart)-> Edit Webpart.
- Editing Tools (Tab) -> Format Text -> HTML -> Edit HTML Source.
Demo Code
<Script type="text/javascript">
var strStatusID;function showInfo()
{
strStatusID = SP.UI.Status.addStatus("Information : ", "<img src='/_Layouts/Images/STS_ListItem_43216.gif' align='absmiddle'> <font color='#AA0000'>Registration process <i>completed</i>.</font>", true);
SP.UI.Status.setStatusPriColor(strStatusID, "yellow");
}
function appendInfo()
{
SP.UI.Status.appendStatus(strStatusID, " Next : ", " <b>You can <a href='Login.aspx'>Login Now</a>", false);
SP.UI.Status.setStatusPriColor(strStatusID, "blue");
}function updateInfo()
{
SP.UI.Status.updateStatus(strStatusID, "Status Update: This content updated with " + strStatusID + " using updateStatus");
SP.UI.Status.setStatusPriColor(strStatusID, "green");
}function updateInfoRed()
{
SP.UI.Status.setStatusPriColor(strStatusID, "red");
}function removeInfo()
{
SP.UI.Status.removeStatus(strStatusID);
}function removeAllInfos()
{
SP.UI.Status.removeAllStatus(true);
}</Script>
<div class="ms-toolpanefooter">
<input type="button" onclick="Javascript:showInfo();" value="Show Info" class="UserButton" />
<input type="button" onclick="Javascript:appendInfo()" value="Append Info" class="UserButton" /> <input type="button" onclick="Javascript:updateInfo()"value="Update Info" class="UserButton" />
<input type="button" onClick="Javascript:updateInfoRed()" value="Make Red" class="UserButton" /> <input type="button" onClick="Javascript:removeInfo()" value="Remove Info" class="UserButton"/>
<input type="button" onClick="Javascript:removeAllInfos()" value="Remove All Infos" class="UserButton"/>
</div>
<Script type="text/javascript">
var strStatusID;function showInfo()
{
strStatusID = SP.UI.Status.addStatus("Information : ", "<img src='/_Layouts/Images/STS_ListItem_43216.gif' align='absmiddle'> <font color='#AA0000'>Registration process <i>completed</i>.</font>", true);
SP.UI.Status.setStatusPriColor(strStatusID, "yellow");
}
function appendInfo()
{
SP.UI.Status.appendStatus(strStatusID, " Next : ", " <b>You can <a href='Login.aspx'>Login Now</a>", false);
SP.UI.Status.setStatusPriColor(strStatusID, "blue");
}function updateInfo()
{
SP.UI.Status.updateStatus(strStatusID, "Status Update: This content updated with " + strStatusID + " using updateStatus");
SP.UI.Status.setStatusPriColor(strStatusID, "green");
}function updateInfoRed()
{
SP.UI.Status.setStatusPriColor(strStatusID, "red");
}function removeInfo()
{
SP.UI.Status.removeStatus(strStatusID);
}function removeAllInfos()
{
SP.UI.Status.removeAllStatus(true);
}</Script>
<div class="ms-toolpanefooter">
<input type="button" onclick="Javascript:showInfo();" value="Show Info" class="UserButton" />
<input type="button" onclick="Javascript:appendInfo()" value="Append Info" class="UserButton" /> <input type="button" onclick="Javascript:updateInfo()"value="Update Info" class="UserButton" />
<input type="button" onClick="Javascript:updateInfoRed()" value="Make Red" class="UserButton" /> <input type="button" onClick="Javascript:removeInfo()" value="Remove Info" class="UserButton"/>
<input type="button" onClick="Javascript:removeAllInfos()" value="Remove All Infos" class="UserButton"/>
</div>
Status bar is used at client side(browser) to display message. If you want to fetch data from status bar then use a hidden variable and assign same value which u pass to status bar via Java Script.
If you want to pass data from Server side to client side then
Add the below function in Javascript.
function showInfo(strMessage)
{
strStatusID = SP.UI.Status.addStatus(strMessage, true);
SP.UI.Status.setStatusPriColor(strStatusID, "yellow");
}
Add a label "lblScripter"
Then in Server Side Code add
lblScripter.Text = "<Script language='javascript;>showInfo('" + strYourMessage + "');</script>";
This will invoke the Javascript and show the statusbar.
If you want to pass data from Server side to client side then
Add the below function in Javascript.
function showInfo(strMessage)
{
strStatusID = SP.UI.Status.addStatus(strMessage, true);
SP.UI.Status.setStatusPriColor(strStatusID, "yellow");
}
Add a label "lblScripter"
Then in Server Side Code add
lblScripter.Text = "<Script language='javascript;>showInfo('" + strYourMessage + "');</script>";
This will invoke the Javascript and show the statusbar.
<SharePoint:SPShortcutIcon ID="SPShortcutIcon1" runat="server" IconUrl="/_layouts/images/favicon.ico"/>
...
..
Then, just above </head>, add the following:
<link rel="shortcut icon" type="image/x-icon" href="/_layouts/images/favicon.ico" />
<link rel="icon" type="image/ico" href="/_layouts/images/favicon.ico" />
<link rel="icon" type="image/png" href="/_layouts/images/favicon.png" >