Tags: , , | Categories: asp.net mvc, development Posted by pieterg on 5/24/2010 8:06 PM | Comments (0)

For those who have not yet seen Stackoverflow or Twitter’s Notification Panels. You are missing out.
image

It’s a neat way to display messages to your users without being too intrusive.

There has been quite a lot of noise regarding ASP.NET MVC with the release of version 2.0. Not to mention the amount of noise the JQuery community has been making. This usually follows by the line, “JQuery is the best thing since sliced bread :)”

Since ASP.NET MVC is not a replacement for ASP.NET Webforms, let’s explore how we can incorporate a notification bar in ASP.NET Webforms.

You can use the following method with any JQuery type notification panel/bar but for this sample grab the Notify Bar from Dmitri Smirnov.

1. Include the jquery.notifyBar.css and jquery.notifyBar.js in your master page
2. Add a static class to your project e.g. (Note the use of extension methods here)

/// <summary>
/// Notification Helper
/// </summary>
public static class NotificationHelper
{
	/// <summary>
	/// Show Message
	/// </summary>
	/// <param name="message"></param>
	public static void ShowNotification(this System.Web.UI.Page page, string message)
	{
		page.ClientScript.RegisterStartupScript(typeof(Page),
												"notificationScript",
												"<script>$(function () {$.notifyBar({html: '"+message+@"',delay: 2000,animationSpeed: 'normal'});});</script>");
	}
}

Now in your Pages you could just call the

Page.ShowNotification(“Hello World!”);