ASP.NET Panel 子类未正确显示在设计器中
我对 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可能想浏览一下有关 “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.