Custom field and UpdateFieldValueInItem()

Custom field and UpdateFieldValueInItem()

Recently I was developing a custom field. To store modified values, the UpdateFieldValueInItem method has to be overwritten.

In a normal way of clicking the submit/save button, the method is called and I can adjust the value for the field within the current item. The changes are submitted to the database later.

But what if you want to modify items outside of the current item? Sure, you can do so would you think. But you’ll need to consider the scenario that the user does not click submit/save. The method is called on every postback. The PeoplePicker will cause a postback, when it validates its values. There might be other controls as well, which behave this way.

My problem was that I could not modify items, other then the current, without checking if submit/save was clicked. I ended up checking the form for the control, that triggered the postback. If this value is “SaveItem”, I am good.

/// <summary>
/// Updates the underlying value of the field to the latest user-set value. 
/// </summary>
public override void UpdateFieldValueInItem()
	// do not trigger logic, if a post without submit occures. e.g. by PeoplePicker
	if (Context.Request.Form["__EVENTTARGET"].Contains("SaveItem"))

So if you need to know if the item is currently being saved or if you are within a regular postback, look at your form 🙂

Leave a Reply