![]() ![]() |
There are two types of Web Controls: standard .NET Web Controls which inherit from System.Web.UI.WebControls.WebControl and generally override the method with signature protected void Render( HtmlTextWriter), and Sitecore Web Controls which inherit from Sitecore.Web.UI.WebControl and generally override protected void DoRender( HtmlTextWriter ). The advantages and disadvantages of the various types of rendering components are listed in the concept resource on Renderings.
First create the Web Control in Microsoft® Visual Studio .NET, inheriting from the appropriate base class and overriding the appropriate rendering method. Ensure the assembly (DLL) containing the new Web Control exists in the /bin directory under the Sitecore site’s document root.
Because standard Web Controls cannot be bound to a Placeholder and currently Web Controls cannot be added to a Layout or Sublayout using drag-and-drop, it is not necessary to register them with Sitecore. Edit the Layout or Sublayout which will contain the Web Control, register the tag prefix with a line such as the following:
(replace custom with your own TagPrefix, Namespace and Assembly (the name of the DLL file without the .dll extension). The Web Control can then be invoked from the Layout or Sublayout with a line of code such as the following:
(replace custom with your TagPrefix and MyWebControl with the class name of the Web Control). Once the Layout or Sublayout has been edited in Visual Studio .NET or another text editing program it should no longer be edited with the browser-based WYSIWYG editor (Layout Editor).
The same approach can be used for Sitecore Web Controls unless they need to be bound to a Placeholder. To bind Sitecore Web Controls to Placeholders, the control must be registered with Sitecore as a Rendering. Unfortunately this wizards has not been completed:
- In content editor, change the first step of the treecrumb to Layout.
- Expand the Renderings node and select an existing Rendering.
- From the New menu select Add from Template.
- Select System, Layout, Renderings and Webcontrol.
- Move the new Rendering from under the existing Rendering to the main Renderings so that it is not a child of another Rendering.
- Complete the properties of the new Rendering.
- Assembly: the name of the assembly containing the Web Control (the file name of the DLL without the .dll extension)
- Namespace: the namespace containing the class representing the Web Control
- Tag: the class name of the Web Control
- TagPrefix: the tag prefix to associate with the assembly.
- Associate the new Rendering with a Placeholder key for Templates and/or Items just as you would a Sublayout or XSL Rendering.
As a shortcut for registering additional Sitecore Web Control Renderings, duplicate an existing Web Control Rendering and change its properties (starting at step 6 above).
![](/SdnArchive/images/sdn5/prev.gif)
![](/SdnArchive/images/sdn5/next.gif)