代码是自我解释的:
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's too late for that"
// how do I throw this message to UI??
}
}
}
我正在使用Umbraco 6。
答案 0 :(得分:1)
根据评论,这是一个模糊的问题,有许多可能的解决方案。很难看清楚你需要什么,但我会尽力理解。
Umbraco 6的一个突出缺点是,语音气泡会显示自定义信息,但Umbraco自己会立即覆盖它们,但你现在可以轻松地做到这一点(感谢我的朋友Ali为代码source并在v6.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 :(得分:0)
试试这个
//validation message: "it's too late for that"
// how do I throw this message to UI??
e.Messages.Add(new EventMessage("validation message", "it's too late for that", EventMessageType.Error));