How to implement a custom panel with INamingContainer?(如何使用 INamingContainer 实现自定义面板?)
问题描述
我正在尝试实现一个可用作命名容器的自定义面板控件.到目前为止,这就是我所做的.
I'm trying to implement a custom panel control that would act as a naming container. So far here is so what I've done.
首先这是我的自定义控件,MyPanel...
First this is my custom control, MyPanel...
[ToolboxData("<{0}:MyPanel runat=server></{0}:MyPanel>")]
public class MyPanel: Panel, INamingContainer
{
}
我尝试像这样使用它:
<cc1:MyPanel ID="A" runat="server">
<asp:HyperLink ID="TestHyperLink" runat="server" />
</cc1:MyPanel>
<cc1:MyPanel ID="B" runat="server">
<asp:HyperLink ID="TestHyperLink" runat="server" />
</cc1:MyPanel>
显然它不起作用,那太容易了.ASP.net 仍然抱怨有 2 个 DocumentHyperLink:
Obviously it doesn't work, that would have been too easy. ASP.net still complains about there being 2 DocumentHyperLink:
The ID 'DocumentHyperLink' is already used by another control.
我应该如何解决这个问题?
How am I supposed to approach this problem?
谢谢.
推荐答案
听起来您可能会受益于模板化控件设计,而不是面板设计.以下是一些开始使用模板化控件的资源:
It sounds like you might benefit from a templated control design, instead of from a Panel design. Here are some resources to get started with templated controls:
- 模板化用户控制:http://msdn.microsoft.com/en-us/library/36574bf6.aspx
- 模板化服务器控制:http://msdn.microsoft.com/en-us/library/aa478964.aspx
模板化设计的吸引力在于允许在另一个模板中重复服务器控件 ID.
The appeal of templated designs is that repeating a server control ID from one template in another is permitted.
这篇关于如何使用 INamingContainer 实现自定义面板?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何使用 INamingContainer 实现自定义面板?


- 如何用自己压缩一个 IEnumerable 2022-01-01
- MoreLinq maxBy vs LINQ max + where 2022-01-01
- 带有服务/守护程序应用程序的 Microsoft Graph CSharp SDK 和 OneDrive for Business - 配额方面返回 null 2022-01-01
- 输入按键事件处理程序 2022-01-01
- 在哪里可以找到使用中的C#/XML文档注释的好例子? 2022-01-01
- C# 中多线程网络服务器的模式 2022-01-01
- Web Api 中的 Swagger .netcore 3.1,使用 swagger UI 设置日期时间格式 2022-01-01
- C#MongoDB使用Builders查找派生对象 2022-09-04
- WebMatrix WebSecurity PasswordSalt 2022-01-01
- 良好实践:如何重用 .csproj 和 .sln 文件来为 CI 创建 2022-01-01