Custom Controls & Reusable UI Components in .NET — Web Forms to Blazor
Pick the right reuse tool
Web Forms: user control (one app) → custom/composite control (many apps) · MVC 5: partial/display template → HTML helper → child action · Core: partial → tag helper → view component → Razor Class Library · Blazor: component (+ library) · WinForms/WPF: UserControl → custom control.
Web Forms control essentials
WebControl + RenderContents · ViewState-backed properties · CompositeControl.CreateChildControls + INamingContainer · events · ControlState · [ToolboxData].
Core essentials
Tag helper: [HtmlTargetElement], Process(Async), @addTagHelper · View component: InvokeAsync, Views/Shared/Components/Name/Default.cshtml, <vc:name>.
Blazor essentials
[Parameter] · EventCallback · RenderFragment / RenderFragment<T> · @typeparam · @bind-Value = Value + ValueChanged · CascadingValue · lifecycle methods · @key · Virtualize.
Good component rules
Small API · data in, events out · encode output · accessible · styleable · tested · versioned.