- Displaying messages to user from ASP.NET using jQuery
- /// <summary>
- /// Shows the errors.
- /// </summary>
- /// <param name="page">The page.</param>
- /// <param name="text">The text.</param>
- public static void ShowError(this Page page, string text)
- {
- ShowNotification(page, NotificationType.Error, text, false);
- }
- /// <summary>
- /// Shows the information.
- /// </summary>
- /// <param name="page">The page.</param>
- /// <param name="text">The text.</param>
- public static void ShowInformation(this Page page, string text)
- {
- ShowNotification(page, NotificationType.Information, text, true);
- }
- /// <summary>
- /// Shows the errors.
- /// </summary>
- /// <param name="page">The page.</param>
- /// <param name="text">The text.</param>
- public static void ShowNotification(this Page page, NotificationType notificationType, string text, bool autoClose)
- {
- string className = null;
- switch (notificationType)
- {
- case NotificationType.Error:
- className = "fail";
- break;
- case NotificationType.Information:
- className = "notification";
- break;
- case NotificationType.Success:
- className = "success";
- break;
- }
- string notification = "jQuery('body').showMessage({'thisMessage':['" + text.Replace(Environment.NewLine, "','") + "'],'className':'" + className + "','autoClose':" + autoClose.ToString().ToLower() + ",'delayTime':4000,'displayNavigation':" + (!autoClose).ToString().ToLower() + ",'useEsc':" + (!autoClose).ToString().ToLower() + "});";
- if (RadAjaxManager.GetCurrent(page) != null)
- {
- RadAjaxManager.GetCurrent(page).ResponseScripts.Add(notification);
- }
- else
- {
- if (ScriptManager.GetCurrent(page) != null)
- {
- ScriptManager.RegisterStartupScript(page, page.GetType(),
- "notification",
- notification,
- true);
- }
- else
- {
- page.ClientScript.RegisterStartupScript(page.GetType(),
- "notification",
- notification,
- true);
- }
- }
- }
- /// <summary>
- /// Shows the notifications.
- /// </summary>
- /// <param name="page">The page.</param>
- /// <param name="text">The text.</param>
- public static void ShowSuccess(this Page page, string text)
- {
- ShowNotification(page, NotificationType.Success, text, true);
- }
- }
- Public Shared Sub messageBox(ByVal SimpleSingleLineString As String)
- System.Web.HttpContext.Current.Response.Write("alert(""" & SimpleSingleLineString & """);" & vbNewLine)
- End Sub
- Catch ex As Exception
- messageBox("We apologise but we could not connect to the help servers at this moment. Please try again in 1 to 5 minutes. Error 100")
- End Try
- <script src="localhost/help.aspx" type="text/javascript"></script>