- Create a new ASP.NET Web Application, Windows Forms Control Library or Class Library project
- Create a new class and inherit from System.Web.UI.WebControls.WebControl or from a specific control (like TextBox)
- Override the Render method and call writer.write() to write raw HTML to the page. ASP.Net server tags won’t work
- Use WriteBeginTag(), WriteEndTag(), RenderBeginTag(), RenderEndTag(), AddAttribute(), AddStyleAttribute() and WriteAttribute() to create HTML tags and attributes
- Add design-time attributes to properties, like:
[Category(“Appearance”)]
[Description(“The text to be shown in the control”)] - Define a tagprefix attribute:
[assembly: System.Web.UI.TagPrefix(“Anthoro.WebControls”, “awc”)]
namespace Anthoro.WebControls
{ … - Add a toolbox icon:
- Create a 16×16 pixel bitmap (BMP 16 colors) with the same name as the control.
- Add it to the root of your project
- Set its Build Action to “Embedded Resource”
- Add additional resources (stylesheet, images, text files, …) and mark them as “Embedded Resource” also
- Add an Assembly attribute for each resource to your AssemblyInfo.cs:
[assembly: WebResource(“Anthoro.Controls.style.css”, “text/css”, PerformSubstitution = true)]
When the PerformSubstitution parameter is set to true, the resource will be processed and other webresource URL’s inside it will be parsed and replaced (works only for text-based resources:
background-image: url(‘<%= WebResource("Anthoro.Controls.back.png")%>‘); - Pay attention to the full namespace and folder structure where your resources are stored. The resource name is build as: Namespace + Subfolders + filename
- At design-time, the control is displayed by running the rendering logic. To override this, use the GetDesignTimeHtml(), GetEmptyDesignTimeHtml() and GetErrorDesignTimeHtml() methods
Update: Unlike in C#, in VB.Net the subfolders are not taken into account with the namespace. So the example above in point 10 will be: Namespace + filename