2011-07-19 114 views
2

我創建了一個自定義字段類型,我覺得沒有任何錯誤,becouse它是如此簡單,但在形式不顯示字段框(見PIC)的Sharepoint自定義字段

pic

.ascx文件:

<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> 

字段類型的文件:

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; 
     } 
    } 
} 
} 

和控制文件:

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"; 
     } 
    } 
} 
} 

正如你所看到的TextBox沒有顯示。

+0

對於SharePoint相關的問題,你有http://sharepoint.stackexchange.com/ – Dante

回答

3

看起來像控件設置爲只呈現SPControlMode.Display。您的屏幕截圖顯示EditNew模式

它看起來像你想覆蓋RenderFieldForInput方法

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

    RenderHtmlForDisplay(output, html); 
} 
+0

哦,謝謝,我拷貝了這部分代碼,並不知道它是什麼意思。謝謝。 –

相關問題