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="fi9Db21wb25lbnRzL015RHJvcERvd25MaXN0LmNz" />
</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 页面上使用子类控件?


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