2012-06-09 24 views
1

我創建了一個自定義控件,它需要一個自定義模板。但沒有intellisense的支持,並有這個xhtml錯誤。 Markup of custom control自定義服務器控件 - 如何獲得智能感知支持並清除xhtml錯誤?

我檢查了一些問題; this文章說,我們必須得到它默認情況下。不過,我一直沒有得到它。我錯過了什麼嗎?

這是怎樣的代碼看起來像:

服務器控制:

[ToolboxData("<{0}:CustomTemplateControl runat=server></{0}:CustomTemplateControl>")] 
[Description("My Custom Template Control")] 
public class CustomTemplateControl : WebControl 
{ 
    [TemplateContainer(typeof(CustomTemplateItem))] 
    public ITemplate CustomHeader { get; set; } 

    protected override void CreateChildControls() 
    { 
     if (CustomHeader != null) 
     { 
      CustomHeader.InstantiateIn(this); 
     } 
     base.CreateChildControls(); 
    } 
    public override void RenderBeginTag(HtmlTextWriter writer) 
    { 
     writer.AddAttribute(HtmlTextWriterAttribute.Id, this.ClientID); 
     writer.RenderBeginTag(HtmlTextWriterTag.Label); 

     //base.RenderBeginTag(writer); 
    } 

模板:

public class CustomTemplateItem : Control, INamingContainer 
{ 

} 

回答

1

您必須創建一個描述模式文件您自定義控件並在任何VS項目中引用該模式文件。您使用它。

xhtml不喜歡大寫字符。可能需要使用全部小寫字符來更改自定義控件的屬性。

相關問題