如何在 ASP.NET 页面上使用子类控件?

How to use a Subclassed Control on an ASP.NET Page?(如何在 ASP.NET 页面上使用子类控件?)
本文介绍了如何在 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 页面上使用子类控件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

DispatcherQueue null when trying to update Ui property in ViewModel(尝试更新ViewModel中的Ui属性时DispatcherQueue为空)
Drawing over all windows on multiple monitors(在多个监视器上绘制所有窗口)
Programmatically show the desktop(以编程方式显示桌面)
c# Generic Setlt;Tgt; implementation to access objects by type(按类型访问对象的C#泛型集实现)
InvalidOperationException When using Context Injection in ASP.Net Core(在ASP.NET核心中使用上下文注入时发生InvalidOperationException)
LINQ many-to-many relationship, how to write a correct WHERE clause?(LINQ多对多关系,如何写一个正确的WHERE子句?)