【发布时间】:2021-06-03 16:36:58
【问题描述】:
所以我试图在我的 SharePoint 2010 列表中完成这种功能:
我的列表中有一个类型选择字段,它有 7 个值,我希望用户不能将该字段的值从值 2、3、4、5、6、7 更改为值 1。
我已经为该列表编写了一个事件接收器,这是我的代码:
public override void ItemUpdated(SPItemEventProperties properties)
{
base.ItemUpdated(properties);
string beforeStatus = properties.BeforeProperties["Status"].ToString();
string afterStatus = properties.AfterProperties["Status"].ToString();
if (beforeStatus != "1stValue" && afterStatus == "1stValue")
{
properties.Cancel = true;
properties.ErrorMessage = "This isn't allowed.";
}
}
我尝试同时使用ItemUpdated 和ItemUpdating 事件接收器,在调试时我看到事件接收器get 被调用,但beforeStatus 和afterStatus 正在从null两种情况下的项目。
那么,我怎样才能在正确更新之前和之后获取项目字段的值?提前致谢!
注意:字段的内部名称和显示名称都是Status。
【问题讨论】:
标签: c# sharepoint event-receiver