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 实现自定义面板?
基础教程推荐
- c# Math.Sqrt 实现 2022-01-01
- rabbitmq 的 REST API 2022-01-01
- 将 Office 安装到 Windows 容器 (servercore:ltsc2019) 失败,错误代码为 17002 2022-01-01
- MS Visual Studio .NET 的替代品 2022-01-01
- 将 XML 转换为通用列表 2022-01-01
- SSE 浮点算术是否可重现? 2022-01-01
- 如何在 IDE 中获取 Xamarin Studio C# 输出? 2022-01-01
- 为什么Flurl.Http DownloadFileAsync/Http客户端GetAsync需要 2022-09-30
- 有没有办法忽略 2GB 文件上传的 maxRequestLength 限制? 2022-01-01
- 如何激活MC67中的红灯 2022-01-01