开发者

Sharepoint Custom Field

开发者 https://www.devze.com 2023-03-21 03:54 出处:网络
I\'ve created a custom field type, I think there are no mistakes, becouse it\'s so simple, but the field box is not displayed at the form (see pic.)

I've created a custom field type, I think there are no mistakes, becouse it's so simple, but the field box is not displayed at the form (see pic.)

Sharepoint Custom Field

.ascx file:

 <SharePoint:RenderingTemplate ID="MyField" runat="server">
 <Template>
 <asp:TextBox ID="TextField" MaxLength="255" runat="server" BackColor="Pink"
 Font-Bold="true" BorderStyle="Dotted" BorderColor="DarkBlue" TextMode="MultiLine" />
 </Template>
 </SharePoint:RenderingTemplate>

Field Type file:

namespace 开发者_开发知识库MyCustomField.CustomField
{
class SPFieldMyCustomField : SPFieldMultiLineText
{

    public SPFieldMyCustomField(SPFieldCollection fields, string fieldName) : base(fields, fieldName)
    {
    }

    public SPFieldMyCustomField(SPFieldCollection fields, string typeName, string displayName)
        : base(fields, typeName, displayName)
    {
    }

    public override BaseFieldControl FieldRenderingControl
    {
        get
        {
            BaseFieldControl control = new MyCustomFieldControl();
            control.FieldName = base.InternalName;

            control.ControlMode = SPControlMode.Display;

            return control;
        }
    }
}
}

and Control file:

namespace MyCustomField.CustomField
{
internal class MyCustomFieldControl : RichTextField
{
    protected override void CreateChildControls()
    {
        ControlMode = SPControlMode.Display;

        base.CreateChildControls();
    }

    protected override void RenderFieldForDisplay(HtmlTextWriter output)
    {
        var html = String.IsNullOrEmpty(Item[Field.InternalName] as string) ? "" : Item[Field.InternalName] as string;

        RenderHtmlForDisplay(output, html);
    }

    protected override string DefaultTemplateName
    {
        get
        {
            return "MyField"; 
        }
    } 
}
}

As you can see TextBox isn't displayed.


Looks like the control is setup to only render for SPControlMode.Display. Your screenshot is showing in Edit or New mode

It looks like you'll want to override the RenderFieldForInput method

protected override void RenderFieldForInput(HtmlTextWriter output)
{
    var html = String.IsNullOrEmpty(Item[Field.InternalName] as string) ? "" : Item[Field.InternalName] as string;

    RenderHtmlForDisplay(output, html);
}
0

精彩评论

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

关注公众号