2011-12-21 7 views
0

テンプレート化されたユーザーコントロールMinimalTemplateを作成しました。これは現在、HTMLを "ContentTemplate"プレースホルダーに渡してレンダリングする以外は何もしません。 Visual Studio 2008には、Repeaterなどの組み込みのテンプレートコントロール用に用意されているMinimalTemplateと同じIntellisense機能が必要です。テンプレート付きユーザーコントロールタグのインテリセンス

enter image description here

enter image description here

おそらく関連:私は手動で私のContentTemplateタグを入力することができ、それが構築し、適切に実行されますが、私は、検証エラーが発生します。 this questionのように、ReflectedSchemasフォルダの内容を既に削除しています。

enter image description here

最小限のテンプレートの完全なソース:

MinimalTemplate.ascx

<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="MinimalTemplate.ascx.cs" Inherits="MyProject.MinimalTemplate" %> 
<asp:placeholder runat=server id="contentPlaceHolder" /> 

MinimalTemplate.ascx.cs私は私のMinimalTemplateコードに作ることができますどのような変更

using System.Web.UI; 

namespace MyProject 
{ 
    [ParseChildren(false)] 
    public partial class MinimalTemplate : System.Web.UI.UserControl 
    { 

     [TemplateContainer(typeof(MessageContainer))] 
     [TemplateInstance(TemplateInstance.Single)] 
     public ITemplate ContentTemplate 
     { get; set; } 

     void Page_Init() 
     { 
      if (ContentTemplate != null) 
      { 
       MessageContainer container = new MessageContainer(); 
       ContentTemplate.InstantiateIn(container); 
       contentPlaceHolder.Controls.Add(container); 
      } 
     } 

     public class MessageContainer : Control, INamingContainer { } 
    } 
} 

Visual StudioでContentTemplateタグをオートコンプリートしますか?

答えて

0

Related

[PersistenceMode(PersistenceMode.InnerProperty)]をContentTemplateの属性リストに追加します。それを追加して再構築した後、検証エラーが消え、Intellisenseドロップダウンに "ContentTemplate"が期待通りに現れました。

調査中、このプロパティを2〜3回追加しても何の効果もなかったと確信しています。そのため、VSバリデーターはちょっと薄れていると思います。それはvoodoo programmingですが、Clean/Rebuild Allを実行し、数秒待ってから検証エラーが続くかどうかを確認してください。

(また、このコントロールには、ParseChildren属性は必要ありません)

関連する問題