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.)
.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);
}
精彩评论