5/11/2011

Customizing the Status Bar and the Notification Area, Programming the Dialog Framework : SharePoint 2010

Steps:


1. Create A New Empty SharePoint 2010 Project.

2. Add A New Item, Select An Application Page.

3. Replace The Code In Your ApplicationPage1.aspx File From Below The Page Directive With The Following.

Code :
<%@ Assembly Name="$SharePoint.Project.AssemblyFullName$" %>
<%@ Import Namespace="Microsoft.SharePoint.ApplicationPages" %>
<%@ Register Tagprefix="SharePoint" Namespace="Microsoft.SharePoint.WebControls" Assembly="Microsoft.SharePoint, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
<%@ Register Tagprefix="Utilities" Namespace="Microsoft.SharePoint.Utilities" Assembly="Microsoft.SharePoint, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
<%@ Register Tagprefix="asp" Namespace="System.Web.UI" Assembly="System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" %>
<%@ Import Namespace="Microsoft.SharePoint" %>
<%@ Assembly Name="Microsoft.Web.CommandUI, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="ApplicationPage1.aspx.cs" Inherits="SharePointProject1.Layouts.SharePointProject1.ApplicationPage1" DynamicMasterPageFile="~masterurl/default.master" %>

<asp:Content ID="PageHead" ContentPlaceHolderID="PlaceHolderAdditionalPageHead" runat="server">

</asp:Content>

<asp:Content ID="Main" ContentPlaceHolderID="PlaceHolderMain" runat="server">

<script type="text/javascript">

// Customizing the Status Bar
var sid;
var color = "";

function AppendStatusMethod()
{
SP.UI.Status.appendStatus(sid, "Appended:", " <HTML> <i>My Status Append to " + sid + " using appendStatus </i></HTML> ");
}

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

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

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

function SetStatusColor()
{
if (color=="")
{
color="red";
}
else if (color=="red")
{
color="green";
}
else if (color=="green")
{
color="yellow";
}
else if (color=="yellow")
{
color="blue";
}
else if (color=="blue")
{
color="red";
}

SP.UI.Status.setStatusPriColor(sid, color);
}

function AppendStatus()
{
SP.UI.Status.addStatus("Appended:", " <HTML> <i>My Status Message Append using atBeginning </i></HTML> ", false);
}

function CreateStatus()
{
return SP.UI.Status.addStatus(SP.Utilities.HttpUtility.htmlEncode("My Status Bar Title"), " <HTML><i> My Status Message</i> </HTML> ", true);
}

// Customizing the Notification Area
var notifyid;
function CreateNotification()
{
notifyid = SP.UI.Notify.addNotification(" My HTML Notification ", true, "My Tooltip", "HelloWorld");
alert("Notification id: " + notifyid);
}
function RemoveNotification()
{
SP.UI.Notify.removeNotification(notifyid);
}

// Programming the Dialog Framework
function OpenDialog()
{
var options = SP.UI.$create_DialogOptions();

options.url = SP.Utilities.Utility.getLayoutsPageUrl('customdialog.htm');
options.url += "?Source=" + document.URL;
alert('Navigating to dialog at: ' + options.url);
options.width = 400;
options.height = 300;
options.title = "My Custom Dialog";

options.dialogReturnValueCallback = Function.createDelegate(null, CloseCallback);
SP.UI.ModalDialog.showModalDialog(options);
}

function CloseCallback(result, target)
{
alert('Result from dialog was: ' + result);

if (result === SP.UI.DialogResult.OK)
{
alert('You clicked OK');
}
else if (result == SP.UI.DialogResult.cancel)
{
alert('You clicked Cancel');
}

alert('Target is: ' + target);
}

</script>

<!-- Customizing the Status Bar --> <br /><br />
<input onclick="sid=CreateStatus();alert(sid);" type="button" value="Create Status"/> <br/>
<input onclick="AppendStatus()" type="button" value="Append Status using atBeginning"/> <br/>
<input onclick="AppendStatusMethod()" type="button" value="Append Status using appendStatus"/> <br/>
<input onclick="UpdateStatus()" type="button" value="Update Status using updateStatus"/> <br/>
<input onclick="SetStatusColor()" type="button" value="Cycle Colors"/> <br/>
<input onclick="RemoveStatus()" type="button" value="Remove Single Status"/> <br/>
<input onclick="RemoveAllStatus()" type="button" value="Remove All Status"/> <br/>

<!-- Customizing the Notification Area --> <br /><br />
<input onclick="CreateNotification()" type="button" value="Create Notification" /> <br/>
<input onclick="RemoveNotification()" type="button" value="Remove Notification" /> <br/>

<!-- Programming the Dialog Framework --> <br /><br />
<input onclick="OpenDialog()" type="button" value="Show Dialog"/> <br/>

</asp:Content>

<asp:Content ID="PageTitle" ContentPlaceHolderID="PlaceHolderPageTitle" runat="server">
Application Page
</asp:Content>

<asp:Content ID="PageTitleInTitleArea" ContentPlaceHolderID="PlaceHolderPageTitleInTitleArea" runat="server" >
My Application Page
</asp:Content>

4. Check The Status Messages In The JavaScript And Remove Any Break Lines.

5. Deploy Your Project.

6. view the page by using /_layout/SharePointProject1/ApplicationPage1.aspx

Thanks and Have Fun!!!!!

0 comments: