Skip to content

SharePoint Custom Field Hide Required And Unique Properties

If you want to hide the required and unique settings in your custom field then use the following code in your IFieldEditor class.

SharePoint Field  Required

/// <summary>
/// Handles the Load event of the Page control.
/// </summary>
/// <param name="sender">The source of the event.</param>
/// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param>
protected void Page_Load(object sender, EventArgs e)
{
	ContentPlaceHolder content = Page.Master.FindControl("PlaceHolderMain") as ContentPlaceHolder;
	HideControlById(content, "EnforceUniqueValuesProperty");
	HideControlById(content, "RequiredProperty");
}

/// <summary>
/// Searches for a control recursively and hides it.
/// </summary>
/// <param name="parentControl">The parent control.</param>
/// <param name="id">The identfier of the control to look for.</param>
private static void HideControlById(Control parentControl, string id)
{
	var control = parentControl.FindControl(id);

	if (control == null)
	{
		foreach (Control nextControl in parentControl.Controls)
		{
			HideControlById(nextControl, id);
		}
	}
	else
	{
		control.Visible = false;
	}
}

To get an idea how the column settings page is build up, take a look at the “FldEditEx.aspx” file in the LAYOUTS folder of the 15 hive.

Leave a Reply

Your email address will not be published. Required fields are marked *

By transmitting your comment you agree to our mentioned privacy policy content.

sixteen + two =