如何更改自定义控件的渲染行为作为跨度

Syp*_*ess 8 asp.net custom-server-controls custom-controls

编写自定义控件时,它始终呈现为HTML span元素.如何将其更改为div?

Joh*_*ers 8

从WebControl导出控件,如下所示:

public class MyCustomControl : WebControl {
    public MyCustomControl() : base(HtmlTextWriterTag.Div) {}
}
Run Code Online (Sandbox Code Playgroud)

也就是说,使用接受要使用的标记的基类构造函数.