I have a requirement to add a rich text box in the custom properties of web part. Is it possible to add the rich text editor in custom properties of web part. The following links tells it is not possible: http://social.msdn.microsoft.com/Forums/sharepoint/en-US/c45435d2-95cd-4128-89d1-8717808160be/add-richtext-editor-in-a-webpart-properties?forum=sharepointdevelopment
2 Answers
You should be able to use a Custom Toolpart.
In this question there is a solution (in the actual question):
public class RichTextToolbarProperty : Microsoft.SharePoint.WebPartPages.ToolPart
{
InputFormTextBox textBox;
Panel toolPartPanel;
protected override void CreateChildControls()
{
toolPartPanel = new Panel();
toolPartPanel.GroupingText = "Default text here";
textBox = new InputFormTextBox();
textBox.TextMode = TextBoxMode.MultiLine;
textBox.Rows = 10;
textBox.RichText = true;
textBox.RichTextMode = SPRichTextMode.FullHtml;
BasePublicationWebPart wp = (BasePublicationWebPart)this.ParentToolPane.SelectedWebPart;
textBox.Text = wp.DefaultText;
toolPartPanel.Controls.Add(textBox);
Controls.Add(toolPartPanel);
base.CreateChildControls();
}
public override void ApplyChanges()
{
BasePublicationWebPart wp = (BasePublicationWebPart)this.ParentToolPane.SelectedWebPart;
wp.DefaultText = textBox.Text;
}
}
and in the webpart:
public abstract class BasePublicationWebPart : Microsoft.SharePoint.WebPartPages.WebPart
{
public string DefaultText
{
get
{
return _defaultText;
}
set { _defaultText = value; }
}
public override ToolPart[] GetToolParts()
{
ToolPart[] allToolParts = new ToolPart[3];
WebPartToolPart standardToolParts = new WebPartToolPart();
CustomPropertyToolPart customToolParts = new CustomPropertyToolPart();
allToolParts[0] = standardToolParts;
allToolParts[1] = customToolParts;
allToolParts[2] = new MyCustomProperty.RichTextToolbarProperty();
return allToolParts;
}
-
thanks for the clarification. If you have any article describing all the details then please give that. I am little bit confused with the article you have pointed.– SushriCommented Jan 20, 2014 at 11:34
-
I have given you most of the code, and there are two links to more information in the post. I can't give you more than that Commented Jan 20, 2014 at 11:35
-
Ok thanks Robert. I will try to get some more details from the links and your code.– SushriCommented Jan 20, 2014 at 11:37
Robert's answer is correct if you are building a SharePoint Web Part (i.e. one from Microsoft.SharePoint.WebPartPages). If you are building an ASP.NET Web Part (i.e. one from System.Web.UI.WebControls.WebParts) then you need to build a custom EditorPart, not a custom ToolPart. The code is very similar to what Robert has shown.
I cover this in Advanced SharePoint Web Part Development. The recording is four years old but the techniques still apply.