Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Conflicts:
	.gitignore
	jQueryNotification.suo
	jQueryNotification/bin/jQueryNotification.dll
	jQueryNotification/bin/jQueryNotification.pdb
	jQueryNotification/obj/Debug/jQueryNotification.dll
	jQueryNotification/obj/Debug/jQueryNotification.pdb
  • Loading branch information
EmadMokhtar committed Feb 20, 2012
2 parents 0697560 + 3821bb6 commit f3bace2
Show file tree
Hide file tree
Showing 19 changed files with 226 additions and 137 deletions.
50 changes: 49 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
<<<<<<< HEAD
obj
bin
_Resharper.*
Expand All @@ -7,4 +8,51 @@ _Resharper.*
*.suo
*.cache
*~
*.swp
*.swp
=======
obj/
bin/
Bin/
Obj/
.svn/
.idea/
debug/
release/
_ReSharper.*
*.csproj.user
*.user
*.suo
*.orig
*.cache
*.vs10x
*~
*.swp
*-log.txt*

.DS_Store
*.gpState

*result.xml
*Result.xml
lint.db
*testresult.xml

~$*.*
*web.log*
*.log
*.bak
*.vs10x
*Thumbs.db
.metadata/
.preprocessed/
.settings/
deliverables/
*.BASE
*.REMOTE
*.LOCAL
*.orig

*.webtestresult

*.docstates
>>>>>>> 3821bb6e072aab8fdecba4552065566f479e3fa5
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
A fork of Emad Mokhtar(<a href="http://twitter/EmadMokhtar">@EmadMokhtar</a>)'s blog post on ASP.NET webforms use of jQuery notification.

**Enad's original blog post:**
http://www.emadmokhtar.com/2012/02/using-notification-in-asp-net-webforms/

**Emad's original github repository:**
https://github.com/EmadMokhtar/jQuery-Notification

**jQuery Plugin used in both original and forked code:**
http://www.givainc.com/labs/jnotify_jquery_plugin.htm
9 changes: 0 additions & 9 deletions jQueryNotification.sln
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,6 @@ Microsoft Visual Studio Solution File, Format Version 11.00
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "jQueryNotification", "jQueryNotification\jQueryNotification.csproj", "{A21FCA4B-74EE-468C-8EAB-880141CEB3CC}"
EndProject
Global
GlobalSection(TeamFoundationVersionControl) = preSolution
SccNumberOfProjects = 2
SccEnterpriseProvider = {4CA58AB2-18FA-4F8D-95D4-32DDF27D184C}
SccTeamFoundationServer = http://emadmokhtar-ws:8080/tfs/defaultcollection
SccLocalPath0 = .
SccProjectUniqueName1 = jQueryNotification\\jQueryNotification.csproj
SccProjectName1 = jQueryNotification
SccLocalPath1 = jQueryNotification
EndGlobalSection
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
Expand Down
Binary file removed jQueryNotification.sln.docstates.suo
Binary file not shown.
10 changes: 0 additions & 10 deletions jQueryNotification.vssscc

This file was deleted.

12 changes: 10 additions & 2 deletions jQueryNotification/Default.aspx
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="jQueryNotification.Default" %>

<%@ Register src="SampleUserControl.ascx" tagPrefix="controls" tagName="SampleUserControl" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
Expand All @@ -12,15 +14,18 @@

<body>
<form id="form" runat="server">
<asp:ScriptManager runat="server" EnablePartialRendering="True"></asp:ScriptManager>
<div>

<asp:UpdatePanel runat="server" UpdateMode="Conditional">
<ContentTemplate>
<asp:Button ID="btnSuccess" runat="server" Text="Successful Notification"
onclick="btnSuccess_Click" />
<asp:Button ID="btnWraning" runat="server" Text="Warning Notification"
onclick="btnWraning_Click" />
<asp:Button ID="btnError" runat="server" Text="Error Notification"
onclick="btnError_Click" />

</ContentTemplate>
</asp:UpdatePanel>
</div>
<div>

Expand All @@ -32,6 +37,9 @@
Text="Delayed Error Notification" onclick="btnDelayedError_Click" />

</div>

<controls:SampleUserControl runat="server" ID="sampleUserControl" />

</form>
</body>
</html>
10 changes: 5 additions & 5 deletions jQueryNotification/Default.aspx.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
using System;
using jQueryNotification.Helper;
using JqueryNotification;

namespace jQueryNotification
{
Expand All @@ -12,10 +12,10 @@ protected void Page_Load(object sender, EventArgs e)

protected void btnSuccess_Click(object sender, EventArgs e)
{
this.ShowSuccessfulNotification("Success Notification");
this.ShowSuccessfulNotification("Success Notification'); alert('me & you');");
}

protected void btnWraning_Click(object sender, EventArgs e)
protected void btnWraning_Click(object sender, EventArgs e)
{
this.ShowWarningNotification("Warning Notification");
}
Expand All @@ -27,12 +27,12 @@ protected void btnError_Click(object sender, EventArgs e)

protected void btnDelayedSuccess_Click(object sender, EventArgs e)
{
this.ShowSuccessfulNotification("Success Notification",5000);
this.ShowSuccessfulNotification("Success Notification", 5000);
}

protected void btnDelayedWarning_Click(object sender, EventArgs e)
{
this.ShowWarningNotification("Warning Notification",5000);
this.ShowWarningNotification("Warning Notification", 5000);
}

protected void btnDelayedError_Click(object sender, EventArgs e)
Expand Down
9 changes: 9 additions & 0 deletions jQueryNotification/Default.aspx.designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

110 changes: 50 additions & 60 deletions jQueryNotification/Helper/NotificationHelper.cs
Original file line number Diff line number Diff line change
@@ -1,83 +1,73 @@
using System.Web.UI;
using System;
using System.Globalization;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace jQueryNotification.Helper
namespace JqueryNotification
{
public static class NotificationHelper
public static class NotificationExtensions
{
/// <summary>
/// Shows the successful notification.
/// </summary>
/// <param name="page">The page.</param>
/// <param name="message">The message.</param>
public static void ShowSuccessfulNotification(this Page page, string message)
public static void ShowNotification(this Control control, NotificationType notificationType, string message, TimeSpan timeBeforeHiding)
{
page.ClientScript.RegisterStartupScript(page.GetType(), "notificationScript",
"<script type='text/javascript'> $(document).ready(function () { $.jnotify('" +
message + "'); });</script>");
var totalNotificationShowingMilliseconds = timeBeforeHiding.TotalMilliseconds;
var jNotifyDelay = totalNotificationShowingMilliseconds > 0
? totalNotificationShowingMilliseconds.ToString(CultureInfo.InvariantCulture)
: "undefined"; // equal to not adding anything

var notificationScript =
string.Format(
"$( function () {{ if(typeof $.jnotify === 'function') {{ $.jnotify('{0}', '{1}', {2}); }} }} );",
HttpUtility.JavaScriptStringEncode(message), notificationType.ScriptKey, jNotifyDelay);

// Allow adding multiple notifications by making the key unique
var scriptKey = Guid.NewGuid().ToString();

// Adding the call to the pre-render event of the page, so that multiple notification calls
// are added in the same order they are rendered in the page, not the order the calls are processed in page life cycle
control.PreRender += new EventHandler
((sender, e) =>
// Note that we need to use ScriptManager to be UpdatePanel friendly
// This will still work even if there is no ScriptManager on the page
ScriptManager.RegisterStartupScript(control, control.GetType(), scriptKey,
notificationScript,
// saves us from adding <script> in string and making it harder to re
addScriptTags: true));
}

public static void ShowNotification(this Control currentControl, NotificationType notificationType, string message)
{
ShowNotification(currentControl, notificationType, message, TimeSpan.FromMilliseconds(0));
}

public static void ShowSuccessfulNotification(this Control currentControl, string notificationMessage)
{
ShowNotification(currentControl, NotificationType.Success, notificationMessage);
}

/// <summary>
/// Shows the warning notification.
/// </summary>
/// <param name="page">The page.</param>
/// <param name="message">The message.</param>
public static void ShowWarningNotification(this Page page, string message)
public static void ShowWarningNotification(this Control currentControl, string notificationMessage)
{
page.ClientScript.RegisterStartupScript(page.GetType(), "notificationScript",
"<script type='text/javascript'> $(document).ready(function () { $.jnotify('" +
message + "', 'warning'); });</script>");
ShowNotification(currentControl, NotificationType.Warning, notificationMessage);
}

/// <summary>
/// Shows the error notification.
/// </summary>
/// <param name="page">The page.</param>
/// <param name="message">The message.</param>
public static void ShowErrorNotification(this Page page, string message)
public static void ShowErrorNotification(this Control currentControl, string notificationMessage)
{
page.ClientScript.RegisterStartupScript(page.GetType(), "notificationScript",
"<script type='text/javascript'> $(document).ready(function () { $.jnotify('" +
message + "', 'error'); });</script>");
ShowNotification(currentControl, NotificationType.Error, notificationMessage);
}

/// <summary>
/// Shows the successful notification.
/// </summary>
/// <param name="page">The page.</param>
/// <param name="message">The message.</param>
/// <param name="delayTimeSpan">The delay time span in millisecond.</param>
public static void ShowSuccessfulNotification(this Page page, string message, int delayTimeSpan)
public static void ShowSuccessfulNotification(this Control currentControl, string notificationMessage, int milliseondsBeforeHiding)
{
page.ClientScript.RegisterStartupScript(page.GetType(), "notificationScript",
"<script type='text/javascript'> $(document).ready(function () { $.jnotify('" +
message + "', " + delayTimeSpan + " ); });</script>");
ShowNotification(currentControl, NotificationType.Success, notificationMessage, TimeSpan.FromMilliseconds(milliseondsBeforeHiding));
}

/// <summary>
/// Shows the warning notification.
/// </summary>
/// <param name="page">The page.</param>
/// <param name="message">The message.</param>
/// <param name="delayTimeSpan">The delay time span in millisecond.</param>
public static void ShowWarningNotification(this Page page, string message, int delayTimeSpan)
public static void ShowWarningNotification(this Control currentControl, string notificationMessage, int milliseondsBeforeHiding)
{
page.ClientScript.RegisterStartupScript(page.GetType(), "notificationScript",
"<script type='text/javascript'> $(document).ready(function () { $.jnotify('" +
message + "', 'warning', " + delayTimeSpan + " ); });</script>");
ShowNotification(currentControl, NotificationType.Warning, notificationMessage, TimeSpan.FromMilliseconds(milliseondsBeforeHiding));
}

/// <summary>
/// Shows the error notification.
/// </summary>
/// <param name="page">The page.</param>
/// <param name="message">The message.</param>
/// <param name="delayTimeSpan">The delay time span in millisecond.</param>
public static void ShowErrorNotification(this Page page, string message, int delayTimeSpan)
public static void ShowErrorNotification(this Control currentControl, string notificationMessage, int milliseondsBeforeHiding)
{
page.ClientScript.RegisterStartupScript(page.GetType(), "notificationScript",
"<script type='text/javascript'> $(document).ready(function () { $.jnotify('" +
message + "', 'error', " + delayTimeSpan + " ); });</script>");
ShowNotification(currentControl, NotificationType.Error, notificationMessage, TimeSpan.FromMilliseconds(milliseondsBeforeHiding));
}
}
}
16 changes: 16 additions & 0 deletions jQueryNotification/Helper/NotificationType.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
namespace JqueryNotification
{
public sealed class NotificationType
{
public string ScriptKey { get; private set; }

private NotificationType(string scriptKey)
{
ScriptKey = scriptKey;
}

public static NotificationType Success = new NotificationType("");
public static NotificationType Error = new NotificationType("error");
public static NotificationType Warning = new NotificationType("warning");
}
}
5 changes: 5 additions & 0 deletions jQueryNotification/SampleUserControl.ascx
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="SampleUserControl.ascx.cs" Inherits="jQueryNotification.SampleUserControl" %>
<div>
<asp:Button ID="btnShowUserControlNotification" runat="server"
Text="Two notifications from user control" onclick="btnShowUserControlNotification_Click" />
</div>
29 changes: 29 additions & 0 deletions jQueryNotification/SampleUserControl.ascx.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using JqueryNotification;

namespace jQueryNotification
{
public partial class SampleUserControl : System.Web.UI.UserControl
{
protected void Page_Load(object sender, EventArgs e)
{

}

protected void btnShowUserControlNotification_Click(object sender, EventArgs e)
{
// Note using <br /> in the message to show you can use HTML in there
// Of course if you are using HTML in real cases, avoid creating it by using strings like this

// Note using 'this' indicating the call belongs to the user control
this.ShowSuccessfulNotification("Called first, but shown second<br />As I belong to some control on the page");
// Note using 'Page' indicating the call belongs to the Page itself
Page.ShowWarningNotification("Called second, but shown first<br />As I belong to the page itself");
}
}
}
Loading

0 comments on commit f3bace2

Please sign in to comment.