Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Jun 20th, 2012  |  syntax: None  |  size: 3.23 KB  |  hits: 17  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. Displaying messages to user from ASP.NET using jQuery
  2. /// <summary>
  3.     /// Shows the errors.
  4.     /// </summary>
  5.     /// <param name="page">The page.</param>
  6.     /// <param name="text">The text.</param>
  7.     public static void ShowError(this Page page, string text)
  8.     {
  9.         ShowNotification(page, NotificationType.Error, text, false);
  10.     }
  11.  
  12.     /// <summary>
  13.     /// Shows the information.
  14.     /// </summary>
  15.     /// <param name="page">The page.</param>
  16.     /// <param name="text">The text.</param>
  17.     public static void ShowInformation(this Page page, string text)
  18.     {
  19.         ShowNotification(page, NotificationType.Information, text, true);
  20.     }
  21.  
  22.     /// <summary>
  23.     /// Shows the errors.
  24.     /// </summary>
  25.     /// <param name="page">The page.</param>
  26.     /// <param name="text">The text.</param>
  27.     public static void ShowNotification(this Page page, NotificationType notificationType, string text, bool autoClose)
  28.     {
  29.         string className = null;
  30.         switch (notificationType)
  31.         {
  32.             case NotificationType.Error:
  33.                 className = "fail";
  34.                 break;
  35.             case NotificationType.Information:
  36.                 className = "notification";
  37.                 break;
  38.             case NotificationType.Success:
  39.                 className = "success";
  40.                 break;
  41.         }
  42.  
  43.         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() + "});";
  44.  
  45.         if (RadAjaxManager.GetCurrent(page) != null)
  46.         {
  47.             RadAjaxManager.GetCurrent(page).ResponseScripts.Add(notification);
  48.         }
  49.         else
  50.         {
  51.             if (ScriptManager.GetCurrent(page) != null)
  52.             {
  53.                 ScriptManager.RegisterStartupScript(page, page.GetType(),
  54.                                                     "notification",
  55.                                                     notification,
  56.                                                     true);
  57.             }
  58.             else
  59.             {
  60.                 page.ClientScript.RegisterStartupScript(page.GetType(),
  61.                                                         "notification",
  62.                                                         notification,
  63.                                                         true);
  64.             }
  65.         }
  66.     }
  67.  
  68.     /// <summary>
  69.     /// Shows the notifications.
  70.     /// </summary>
  71.     /// <param name="page">The page.</param>
  72.     /// <param name="text">The text.</param>
  73.     public static void ShowSuccess(this Page page, string text)
  74.     {
  75.         ShowNotification(page, NotificationType.Success, text, true);
  76.     }
  77. }
  78.        
  79. Public Shared Sub messageBox(ByVal SimpleSingleLineString As String)
  80.     System.Web.HttpContext.Current.Response.Write("alert(""" & SimpleSingleLineString & """);" & vbNewLine)
  81. End Sub
  82.        
  83. Catch ex As Exception
  84.         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")
  85.     End Try
  86.        
  87. <script src="localhost/help.aspx" type="text/javascript"></script>