Programmatically hide show the status bar

13 September 2010 7:03 PM Posted by Mano Mangaldas

Customizing status bar programmatically using Server code


Showing persistent messages using the SharePoint 2010 Status bar

Method 1 - registering client script

private string PageStatusHtml = "This is a custom message. Click here for more details.";

protected override void OnPreRender(EventArgs e)
{
 base.OnPreRender(e);
 ScriptLink.RegisterScriptAfterUI(this.Page, "core.js", true, false);
 ScriptLink.RegisterScriptAfterUI(this.Page, "CUI.js", false, true);
 ScriptLink.RegisterScriptAfterUI(this.Page, "SP.js", false, true);

 this.SetStatusVisibility();
}


private void SetStatusVisibility()
{
 StringBuilder script = new StringBuilder();
 if (!string.IsNullOrEmpty(this.PageStatusHtml))
 {
  script.Append("");
 }
 this.Page.ClientScript.RegisterStartupScript(typeof(SPRibbon), "permstatus", script.ToString(), false);
}

Method 2 - using SPPageStatusSetter

private string PageStatusHtml = "This is a custom message. Click here for more details.";

protected override void CreateChildControls()
{
 base.CreateChildControls();

 status = new SPPageStatusSetter();
 status.AddStatus("My Message", PageStatusHtml, SPPageStatusColor.Blue);
 this.Controls.Add(status);
}

protected override void RenderContents(HtmlTextWriter writer)
{
 status.RenderControl(writer);
}

Hiding a SharePoint 2010 Status bar

public void HideStatusBar()
{
   string script = "document.onreadystatechange=fnRemoveAllStatus; function fnRemoveAllStatus(){removeAllStatus(true)};";
   this.Page.ClientScript.RegisterClientScriptBlock(typeof(HideTheRibbon), "statusBarRemover", script, true);
}


Customizing status bar programatically using client side code

<script type="text/javascript">
function CreateStatus()
{
this.statuthis.statusID =  SP.UI.Status.addStatus(SP.Utilities.HttpUtility.htmlEncode("My Status Bar Title"), "This is a new message", true);
}

function AppendStatusMethod()
{
SP.UI.Status.appendStatus(this.statusID, "Appended:", " This is appended text ");
}

function UpdateStatus()
{
SP.UI.Status.updateStatus(this.statusID, "Updated: HTML updated for " + this.statusID + " using updateStatus");
}

function RemoveStatus()
{
SP.UI.Status.removeStatus(this.statusID);
}

function RemoveAllStatus()
{
SP.UI.Status.removeAllStatus(true);
}

</script>


ref :
http://www.learningsharepoint.com/2010/07/20/customizing-the-status-bar-in-sharepoint-2010/
http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.webcontrols.sppagestatussetter_methods.aspx
http://www.sharepoint4arabs.com/AymanElHattab/Lists/Posts/Post.aspx?List=0b2c413e%2De6fb%2D4c60%2Da12f%2D9ae9bdbd48c8&ID=181

Comments (0)

Post a Comment