Share via


Notification Service Example

This content is no longer actively maintained. It is provided as is, for anyone who may still be using these technologies, with no warranties or claims of accuracy with regard to the most recent product version or service release.

The following example shows how Web Parts can interact in a dashboard through the Notification service. In the example, when a user selects a car in the Web Part on the left, the Web Part on the right displays a simple GIF of that car from CarPoint.

The Web Part, Picture of Car, registers itself for events using the RegisterForEvent function. When registering, the Web Part specifies the namespace and name of the event and the function to call when that event occurs, which is DisplayCarInfo. DisplayCarInfo is a simple function that displays the appropriate picture depending on the selected car.

The following is the content for the Web Part, Picture of Car:

<center>
<div id=car_WPQ_><IMG id=img_WPQ_ border=0 src=""></div>
</center>
<SCRIPT language="JScript">
var sCarSelected;
DDSC.RegisterForEvent("urn:myCompany:Car", "onSelect", DisplayCarInfo);
function DisplayCarInfo(sCarSelected)
{
   switch (sCarSelected) {
      case "BMW" :
         document.all.img_WPQ_.src = _ "http://carpoint.msn.com/merismus/Gallery/c436829a.jpg";
         break;
      case "PORSCHE" :
         document.all.img_WPQ_.src = _ "http://carpoint.msn.com/merismus/Gallery/c437128a.jpg";
      break;
      case "MERCEDES" :
         document.all.img_WPQ_.src = _ "http://carpoint.msn.com/merismus/Gallery/c436231a.jpg";
      break;
   }   
}
</SCRIPT>

The Web Part, Select Car, raises an event whenever a user selects the name of a car. To do this, the Web Part uses the RaiseEvent function, specifying its namespace and the name of the event and passing the value of the item the user selected from the list.

The following is the content of the Web Part, Select Car:

<SELECT ID="CarsForSale" NAME="CarsForSale" SIZE="3" OnClick="SendNotification()" OnKeyUp = "SendNotification()">
<OPTION VALUE="BMW" SELECTED>BMW</OPTION>
<OPTION VALUE="PORSCHE">PORSCHE</OPTION>
<OPTION VALUE="MERCEDES">MERCEDES</OPTION>
</SELECT>
<SCRIPT language="JScript" id=s1>
function SendNotification()
{
   DDSC.RaiseEvent ("urn:myCompany:Car", "onSelect", CarsForSale.value);
}
</SCRIPT>

Because the Web Part, Picture of Car, is registered to receive notification of this event, the function DisplayCarInfo is called with the value that was passed as an argument to RaiseEvent, displaying the picture of the selected car.

See Also

Notification Service | System Notifications (Notification Service)