How to display user interface notification at some Umbraco event?

The code itself explains:

public class TooLateValidator : IApplicationStartupHandler { public TooLateValidator() { ContentService.Saving += ContentService_Saving; } private void ContentService_Saving(IContentService sender, Umbraco.Core.Events.SaveEventArgs<Umbraco.Core.Models.IContent> e) { if(DateTime.Now.Hour > 21){ e.Cancel = true; //validation message: "it too late for that" // how do I throw this message to UI?? } } } 

I am using Umbraco 6.

+4
source share
2 answers

According to the comments, this is a vague question, and there are a number of possible solutions. It's hard to understand what you need, but I will try and understand.

One of the outstanding errors of Umbraco 6 was that the speech bubble displayed user messages, but they would be immediately overwritten by the owner of Umbraco, but now you can do it easily (thanks to my friend Ali for the source code and works for me in version 6.1.6 )

 using System.Web; using System.Web.UI; using Umbraco.Core; using Umbraco.Core.Events; using Umbraco.Core.Models; using Umbraco.Core.Services; using Umbraco.Web.UI; using Umbraco.Web.UI.Pages; public class UmbracoEvents : ApplicationEventHandler { protected override void ApplicationStarting(UmbracoApplicationBase umbracoApplication, ApplicationContext applicationContext) { //Events ContentService.Created += Content_Created; ContentService.Saving += Content_Saving; } private void Content_Saving(IContentService sender, SaveEventArgs<IContent> e) { // 1 JavaScript HttpContext.Current.Response.Write("<script>alert('Saved!');</script>"); e.Cancel = true; } private void Content_Created(IContentService sender, NewEventArgs<IContent> e) { // 2 Umbraco speech bubble var clientTool = new ClientTools((Page)HttpContext.Current.CurrentHandler); clientTool.ShowSpeechBubble(SpeechBubbleIcon.Success, "Warning", "It is to late to do that!"); } } 
+1
source

try it

  //validation message: "it too late for that" // how do I throw this message to UI?? e.Messages.Add(new EventMessage("validation message", "it too late for that", EventMessageType.Error)); 
0
source

Source: https://habr.com/ru/post/1497251/


All Articles