ASP.NET Panel 子类未正确显示在设计器中

发布于 2024-07-24 09:52:04 字数 961 浏览 4 评论 0原文

我对 ASP.NET Panel 控件进行了子类化,以自定义 GroupingText 的呈现。 然而,虽然它在最终输出中看起来很好,但在设计器中却没有正确显示。

我正在做的示例如下:

我还需要做些什么才能使其在设计器中正确显示?

Imports System.Web.UI

Public Class CustomPanel
    Inherits Panel

    Public Overrides Sub RenderBeginTag(ByVal writer As System.Web.UI.HtmlTextWriter)
        Me.AddAttributesToRender(writer)
        Dim tagKey As HtmlTextWriterTag = Me.TagKey
        If (tagKey <> HtmlTextWriterTag.Unknown) Then
            writer.RenderBeginTag(tagKey)
        Else
            writer.RenderBeginTag(Me.TagName)
        End If
        Dim groupingText As String = Me.GroupingText
        If ((groupingText.Length <> 0) AndAlso Not TypeOf writer Is Html32TextWriter) Then
            writer.AddAttribute("class", "heading")
            writer.RenderBeginTag(HtmlTextWriterTag.Div)
            writer.Write(groupingText)
            writer.RenderEndTag()
        End If
    End Sub

End Class

I have subclassed the ASP.NET Panel control to customise the rendering of the GroupingText. However, while it appears fine in the final output, it is not appearing correctly in the designer.

A sample of what I am doing follows:

Is there anything else I need to do to make it appear correctly in the designer?

Imports System.Web.UI

Public Class CustomPanel
    Inherits Panel

    Public Overrides Sub RenderBeginTag(ByVal writer As System.Web.UI.HtmlTextWriter)
        Me.AddAttributesToRender(writer)
        Dim tagKey As HtmlTextWriterTag = Me.TagKey
        If (tagKey <> HtmlTextWriterTag.Unknown) Then
            writer.RenderBeginTag(tagKey)
        Else
            writer.RenderBeginTag(Me.TagName)
        End If
        Dim groupingText As String = Me.GroupingText
        If ((groupingText.Length <> 0) AndAlso Not TypeOf writer Is Html32TextWriter) Then
            writer.AddAttribute("class", "heading")
            writer.RenderBeginTag(HtmlTextWriterTag.Div)
            writer.Write(groupingText)
            writer.RenderEndTag()
        End If
    End Sub

End Class

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

南城追梦 2024-07-31 09:52:04

您可能想浏览一下有关 “Adding Design Time Support to ASP.Net 控件”

只是为了让您知道:创建具有强大设计时支持的自定义服务器控件并不是一件小事。 如果您可以避免使用 UserControl,或者解决缺乏设计时支持的问题,那么您的情况会更好。

通常情况下,这个练习最好留给 以此为生的人

You probably want to take a tour through the MSDN posting about "Adding Design Time Support to ASP.Net controls"

Just to let you know as well: creating custom server controls with robust design time support is not a trivial thing. If you can get away with using a UserControl, or dealing with the lack of design time support you are better off.

More often than not, this is an exercise that is better left to people who do this for a living.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文