asp.net 自定义服务器控件设计时支持
我在设计视图中使用自定义面板控件时遇到问题。重写渲染方法在设计时没有影响。
如果我按如下方式扩展文本框,设计时将显示 div 标签,然后显示文本框控件。对面板控件进行了相同的尝试,但它没有显示带有此处文本的 div。似乎由于面板是一个容器控件,它在设计视图中的工作方式有所不同。真是令人沮丧。关于如何让我的设计时间按照我想要的方式呈现有什么想法吗?
Public Class textboxextend
Inherits TextBox
Protected Overrides Sub Render(ByVal writer As System.Web.UI.HtmlTextWriter)
writer.RenderBeginTag("div")
writer.Write("here")
writer.RenderEndTag()
MyBase.Render(writer)
End Sub
End Class
Public Class panelextend
Inherits Panel
Protected Overrides Sub Render(ByVal writer As System.Web.UI.HtmlTextWriter)
writer.RenderBeginTag("div")
writer.Write("here")
writer.RenderEndTag()
MyBase.Render(writer)
End Sub
End Class
I'm having issues with a custom panel control in design view. Overriding the render method has no affect at design-time.
If I extend a textbox as follows the design time showed the div tag and then the textbox control. Tried the same with the panel control and it did not show the div with the here text in it. Seems since panel is a container control it works differently in design view. Really frustrating. Any ideas on how to get my design-time to render the way I want it to?
Public Class textboxextend
Inherits TextBox
Protected Overrides Sub Render(ByVal writer As System.Web.UI.HtmlTextWriter)
writer.RenderBeginTag("div")
writer.Write("here")
writer.RenderEndTag()
MyBase.Render(writer)
End Sub
End Class
Public Class panelextend
Inherits Panel
Protected Overrides Sub Render(ByVal writer As System.Web.UI.HtmlTextWriter)
writer.RenderBeginTag("div")
writer.Write("here")
writer.RenderEndTag()
MyBase.Render(writer)
End Sub
End Class
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
面板的工作方式与文本框(和大多数控件)不同。没有 Render 方法,因此永远不会调用重写。面板使用RenderBeginTag和RenderEndTag。
您可能还想使用 AddAttributesToRender 方法。
Panel doesn't work the same way as TextBox (and most controls). There is no Render method, so the override is never called. Panel uses RenderBeginTag and RenderEndTag.
You may want to use the AddAttributesToRender method too.