开发者

Sharepoint Webpart Properties / Rich text box?

开发者 https://www.devze.com 2022-12-16 17:27 出处:网络
Is it possible to make a String in a web part properties editable with a rich text box (to be able to use the Bold, etc.) ?

Is it possible to make a String in a web part properties editable with a rich text box (to be able to use the Bold, etc.) ?

UPDATE / SOLUTION

The 1st class is the "Custom property" that should appear in the toolbar

   using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using Microsoft.SharePoint.WebControls;
    using System.Web.UI.WebControls.WebParts;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using Microsoft.SharePoint;    
    namespace MyCustomProperty
    {
        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;
            }

        }
    }

The 2nd class is the WebPart :

using System;
using System.Data;
using System.Text;
using System.Collections.Generic;
using System.Web.UI;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.WebControls;

using System.ComponentModel;
using Microsoft.SharePoint;
using Microsoft.SharePoint.Utilities;
using Microsoft.SharePoint.WebPartPages;

namespace MyWebPart
{

    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;
        }
// ... some usual web part code should go here ... ///


Yes it is, you might want to inspect, how the "Custom Content Editor Web Part" is built: http://www.codeproject.com/KB/sharepoint/Custom_CEWP_4_SharePoint.aspx

0

精彩评论

暂无评论...
验证码 换一张
取 消