Search code examples
sharepoint-2010sharepoint-2007custom-fieldscustom-field-type

sharepoint 2010. SPField set control for edit and preview


I need to add custom editor for my created sharepoint field. How can i set control both for edit mode and preview mode. Will be two different controls!

I found that i can override FieldRenderingControl. But how to determine that current mode is edit or preview?

thanks.


Solution

  • In your custom field render control (BaseFieldControl) check on the member "ControlMode", which is of type SPControlMode.

    protected override void CreateChildControls()
    {
      base.CreateChildControls();
    
      if (ControlMode == SPControlMode.Display)
      {
        // create controls for display view form
      }
      else
      {
        // create controls for edit/new form
      } 
    

    Also have a look on the methods "GetFieldValueAsText()" and "GetFieldValueAsHtml()" inherited from SPField. Since the are used to display the fields content in non-form location. For instance in list view or in the version history.