SDN 有一些代码示例。从本质上讲,WebControls 是 .NET 服务器控件,您可以在其中通过 C# 编写所有业务逻辑和前端代码。这是SDN上名为“Web Controls”的系列:
- 第1部分
- 第2部分
- 第 3 部分
这是一个示例文本控件:
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
等下的类。