如何在 ASP.NET 页面上使用子类控件? [英] How to use a Subclassed Control on an ASP.NET Page?

查看:21
本文介绍了如何在 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 页面上使用子类控件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆