0

I've created field type inherited SPFieldUser with custom rendering control. My problem is: this field doesn't save value if it was provisioned by content type. When I add this field directly in list definition or in list through UI everything fine.

Key point in field implementation is overriding Value function.

public override object Value
    {
        get
        {
            this.EnsureChildControls();

            var userId = this.UserIdControl.Text;
            SPFieldUserValue res = new SPFieldUserValue();
            if (!string.IsNullOrEmpty(userId))
            {
                var userIdArr = userId.Split('|');
                var userIdInt = int.Parse(userIdArr[0]);
                var userLogon = userIdArr[1];
                res = new SPFieldUserValue(SPContext.Current.Web, userIdInt, userLogon);
            }               

            return res;
        }
        set
        {
            this.EnsureChildControls();
            base.Value = value;
        }
    }

This function is called in both situations (Note: User always exists, it never could be null in my code example): when field added by content type and by me, but in first case value doesn't saved.

Could someone help me?

1 Answer 1

0

Problem was in not specified LookupList property (inherits from SPLookupField) for my Custom Column. I'm setting this value in event receiver now. This solved an issue.

Example, field definition from list should looks like solution:

<Field Type="KMSOwner" DisplayName="own" List="UserInfo" Required="FALSE" EnforceUniqueValues="FALSE" ID="{eeaae85e-9f00-42ac-812c-12ebd673f57c}" SourceID="{c54058b0-6bbd-4ce5-8f12-f662d5740da4}" StaticName="own" Name="own" ColName="int1" RowOrdinal="0" />

Key point is List="UserInfo". If field added by content type this property is empty.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.