How to use a Subclassed Control on an ASP.NET Page?(如何在 ASP.NET 页面上使用子类控件?)
问题描述
我已将 DropDownList 子类化以添加特定于我的应用程序的功能:
I've subclassed DropDownList to add functionality specific to my application:
public class MyDropDownList : DropDownList
{
...
}
...然后在 Web.Config 中引用它,我认为事情开始出错了:
... then referenced it in Web.Config, which is where I figure things start to go wrong:
<pages theme="Main">
<controls>
<add tagPrefix="bob" tagName="MyDropDownList" src="~/Components/MyDropDownList.cs" />
</controls>
</pages>
我对它的引用不起作用:
my reference to it does not work:
<tr><td>Category</td>
<td><bob:MyDropDownList runat="server" ID="Category"... />
我最好的线索是编译器错误消息:
and my best clue is the complier error message:
"The file 'src' is not a valid [sic] here because it doesn't expose a type."
我认为我在这里误用了有关如何创建 Web 用户控件的知识.我想要做的是在 ASP.NET 页面上引用这个控件,就像我引用父 DropDownList 一样.重构回包含 DropDownList 的 Web 用户控件是不可取的,因为我想对其应用 RequiredFieldValidator.
I figure I'm misapplying knowledge of how to create a Web User Control here. What I want to be able to do is refer to this control on an ASP.NET page just like I would the parent DropDownList. Refactoring back into a Web User Control that contains a DropDownList is not desirable, because I want to apply a RequiredFieldValidator to it.
推荐答案
<pages theme="Main">
<controls>
<add tagPrefix="bob" namespace="MyProject" assembly="MyProject" />
</controls>
</pages>
这应该可以解决问题.
这篇关于如何在 ASP.NET 页面上使用子类控件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何在 ASP.NET 页面上使用子类控件?
基础教程推荐
- C# 从 List<List<int>> 中删除重 2022-01-01
- 禁止输入少量字符,例如'<'、'&a 2022-01-01
- 我应该在后面的代码中直接使用 Linq To SQL 还是使 2022-01-01
- 当值可以是对象或空数组时反序列化 JSON 2022-01-01
- Azure Functions:CosmosDBTrigger 未在 Visual Studio 中触发 2022-01-01
- WPF 模态进度窗口 2022-01-01
- .NET SerialPort DataReceived 事件未触发 2022-01-01
- 如何使用 .Net 检查 Active Directory 服务器是否已启动并正在运行? 2022-01-01
- Moq It.Is<>不匹配 2022-01-01
- 如果有人提交恶意软件Nuget包怎么办? 2022-01-01
