如何在ASP.NET页面使用一个子类控制? [英] How to use a Subclassed Control on an ASP.NET Page?
问题描述
我的子类的DropDownList
添加特定的功能,我的应用程序:
公共类MyDropDownList:DropDownList的
{
...
}
...然后引用它的Web.Config
,这是我搞清楚这些事情开始出错:
<页面主题=主>
<控制与GT;
<添加标签preFIX =鲍勃变量名=MyDropDownListSRC =〜/组件/ MyDropDownList.cs/>
< /控制>
< /页>
我引用这是行不通的:
< TR>< TD>分类和LT; / TD>
< TD><鲍勃:MyDropDownList =服务器ID =类别... />
和我最好的线索就是编译器错误消息:
文件SRC不是一个有效的[原文]在这里,因为它不公开一个类型。
我的身影,我误用的如何在这里创建一个Web用户控件的知识。我希望能够做的就是参考这个控件的ASP.NET页面上,就像我会父的DropDownList
。重构回包含Web用户控件的DropDownList
是不可取的,因为我想申请一个的RequiredFieldValidator
将其
<页面主题=主>
<控制与GT;
<添加标签preFIX =鲍勃命名空间=MyProject的集结号=MyProject的/>
< /控制>
< /页>
这是应该做的伎俩。
I've subclassed DropDownList
to add functionality specific to my application:
public class MyDropDownList : DropDownList
{
...
}
... 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."
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>
That should do the trick.
这篇关于如何在ASP.NET页面使用一个子类控制?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!