我可以在DocumentEvents.Update.Before事件中更改TreeNode中属性的值吗? [英] Can I change a value of a property in a TreeNode in a DocumentEvents.Update.Before event?

查看:36
本文介绍了我可以在DocumentEvents.Update.Before事件中更改TreeNode中属性的值吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们正在使用的TreeNodes中的特定字段在其兄弟之间必须是唯一的.为了确保它是唯一的,当用户更改并保存它时,我试图更改TreeNode中字段的值.这将导致save事件再次触发,从而调用我的事件处理程序,该事件处理程序将再次触发该事件.这是不希望的循环.

有没有一种方法可以在不触发更新事件的情况下更新treenode?

我能想到的唯一方法是直接对数据库执行sql查询,但我希望有更好的方法.

TreeNode.SubmitChanges(false);和TreeNode.Update();两者都触发DocumentEvents.Update事件,因此无法解决问题.

从Kentico用户界面触发事件或从C#代码触发事件时,我看不到DocumentEventArgs之间有任何区别.

事件处理程序调用:

DocumentEvents.Update.Before += 
uniquePageAliasModule.EnsureUniquePageAliasOnUpdate;

事件处理程序的实现:

treeNode.SetValue((Metadata.MetadataPageUrlPath), path);
treeNode.SubmitChanges(false);

所需:将更改保存到TreeNode,并且不触发DocumentEvents.Update事件

实际:将更改保存到TreeNode并触发DocumentEvents.Update事件

解决方案

您可以使用 RequestStockHelper 递归控制,就像该主题上的旧主题

A specific field in the TreeNodes we are using needs to be unique among its siblings. To ensure that it is unique, I'm trying to change the values of a field in a TreeNode when the user changes and saves it. This causes the save event to fire again, which calls my event handler, which fires the event again. It is an undesired loop.

Is there a way to update the treenode, without firing the update event?

The only way I could think of is performing an sql query directly to the database, but I hope there's a better way.

TreeNode.SubmitChanges(false); and TreeNode.Update(); both fire the DocumentEvents.Update event, so that did not solve the problem.

I don't see any differences between the DocumentEventArgs when the event is fired from the Kentico User Interface or when it is fired from my C# code.

Event handler call:

DocumentEvents.Update.Before += 
uniquePageAliasModule.EnsureUniquePageAliasOnUpdate;

Event handler implementation:

treeNode.SetValue((Metadata.MetadataPageUrlPath), path);
treeNode.SubmitChanges(false);

Desired: Save the changes to the TreeNode and do not fire the DocumentEvents.Update event

Actual: Saves the changes to the TreeNode and fires the DocumentEvents.Update event

解决方案

You can use RequestStockHelper or Recursion Control like it was mentioned in this article. I personally prefer to use RequestStockHelper it works like request context.

You might try DocumentEvents.Update.Continue = false. there is an old topic on that

这篇关于我可以在DocumentEvents.Update.Before事件中更改TreeNode中属性的值吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆