Skip to content

Add TagKey + AddAttributesToRender to CustomControls.WebControl (P2) #492

Description

@csharpfritz

Summary

Web Forms WebControl has a TagKey property (returns HtmlTextWriterTag) and AddAttributesToRender(HtmlTextWriter) method that auto-renders the outer tag. BWFC's CustomControls.WebControl doesn't have these - custom controls must manually render their entire tag structure.

How Web Forms Does It

// Web Forms WebControl.Render() does this automatically:
public override void Render(HtmlTextWriter writer) {
    AddAttributesToRender(writer);  // ID, class, style, custom attrs
    writer.RenderBeginTag(TagKey);   // e.g., HtmlTextWriterTag.Span
    RenderContents(writer);          // subclass content
    writer.RenderEndTag();
}

Subclasses override TagKey to change the outer element and AddAttributesToRender to add custom attributes.

Use Cases

  • StarRating control renders a <span> as outer element with CSS classes
  • NotificationBell renders a <div> with data-* attributes
  • Any custom control that wraps content in a standard HTML element

Proposed Changes

Add to CustomControls.WebControl:

  • Virtual TagKey property (default: HtmlTextWriterTag.Span)
  • Virtual AddAttributesToRender(HtmlTextWriter) - auto-adds ID, CssClass, Style
  • Update Render() to auto-render outer tag

Priority

P2 - Enables cleaner custom control migration and reduces boilerplate tag management.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions