Search This Blog

Friday, February 11, 2011

Prevent a Field Value From Being Edited without Event Handler

In some scenarios, user may ask for a field which should not be editable after information has been added to it. Or many times we may want to disallow user to delete that field. This can be easily achieved through code by changing the properties of SPField object.

//Get the field that you want to update
SPField objSPField = objSPWeb.Fields.GetField("Your Field Title");

if (objSPField != null)

//change the properties
objSPField.AllowDeletion = true;
objSPField.ShowInDisplayForm = true;

objSPField.ShowInListSettings = false;
objSPField.ShowInEditForm = false;
objSPField.ShowInNewForm = true;

No comments:

Post a Comment