SDNにはいくつかのコード例があります。基本的に、WebControlsは.NETサーバーコントロールであり、C#を介してすべてのビジネスロジックとフロントエンドコードを記述します。これが「Webコントロール」と呼ばれるSDNのシリーズです。
- パート1
- パート2
- パート3
TextControlのサンプルは次のとおりです。
protected override void DoRender(HtmlTextWriter output) {
if (ClassAttribute.Length > 0) {
output.AddAttribute(HtmlTextWriterAttribute.Class, ClassAttribute);
}
if (StyleAttribute.Length > 0) {
output.AddAttribute(HtmlTextWriterAttribute.Style, StyleAttribute);
}
output.RenderBeginTag(HtmlTextWriterTag.Div);
string val = string.Empty;
if(_text.Length == 0) {
val = GetFieldValue(_textField);
} else {
val = _text;
}
output.AddAttribute(HtmlTextWriterAttribute.Class, TextClass);
output.AddAttribute(HtmlTextWriterAttribute.Style, TextStyle);
output.RenderBeginTag(HtmlTextWriterTag.Div);
output.Write(val);
output.RenderEndTag();
output.RenderEndTag();
}
編集:内部の組み込みSitecoreコンポーネントがどのように機能するかを理解するには:
Sitecoreは、コントロールの構築方法の詳細を提供しません。Sitecoreはオープンソースではありません。そうは言っても、Sitecoreの人々から、拡張するために何かがどのように機能するかを理解する必要がある場合は、.NET Reflectorを使用してカーネルを逆コンパイルするように言われました(Sitecore.Kernel.dll
)。私はこれを何度も行って、内部のものがどのように機能するかを理解しました。あなたの場合、アセンブリを逆コンパイルして、Sitecore.Web.UI.WebControls
etcの下のクラスを見ることができます。