开发者

Where can Sitecore webcontrol examples be found?

开发者 https://www.devze.com 2023-03-28 19:31 出处:网络
I\'ve been looking over the Sitecore documentation for HtmlControls and WebControls, b开发者_运维技巧ut none of the items have any meaningful descriptions or example code to show how they\'re used or

I've been looking over the Sitecore documentation for HtmlControls and WebControls, b开发者_运维技巧ut none of the items have any meaningful descriptions or example code to show how they're used or what they produce.

I understand how to use simple controls like Text, Date, Image, and Link:

<sc:Text runat="server" ID="content" Field="Content" />

Is there a resource that includes examples for more advanced controls like WebControls.ItemList or HtmlControls.TreePicker to show how they'd be used and what output they produce?


The SDN has some code examples. Essentially, WebControls are .NET server controls where you write all business logic and front-end code via C#. Here's the series on the SDN called "Web Controls":

  1. Part 1
  2. Part 2
  3. Part 3

Here's a sample 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();

}

EDIT: To understand how internal built-in Sitecore components work:

Sitecore is not going to provide the details of how their controls are built. Sitecore is not open source. That being said, I've been told several times by people from Sitecore that if you need to understand how something works to extend it, use the .NET Reflector to de-compile the kernel (Sitecore.Kernel.dll). I've done this many times to figure out how the internal things work. In your case, you can decompile the assembly and look at the classes under Sitecore.Web.UI.WebControls etc.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号