在ASP.NET DropDownList的子类 [英] Subclassing DropDownList in ASP.NET

查看:81
本文介绍了在ASP.NET DropDownList的子类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要继承内置的DropDownList在ASP.NET这样我就可以添加功能,它在我的网页中使用它。我试着用一个用户控件这样做,但发现它并没有暴露出内部的DropDownList(从逻辑上讲,我猜)。我GOOGLE了答案,但无法找到任何东西。

I want to subclass the built-in DropDownList in ASP.NET so that I can add functionality to it and use it in my pages. I tried doing this with a UserControl but found that it doesn't expose the internal DropDownList (logically, I guess). I've googled for the answer but can't find anything.

我来尽可能编写实际的类,并有可能从DropDownList的子类,但我无法将文件登记在我的ASP.NET页面,并在源视图中使用它。也许我缺少一些特性在我的课?

I've come as far as writing the actual class, and it's possible to subclass from DropDownList but I'm unable to register the file in my ASP.NET page and use it in the source view. Maybe I'm missing some properties in my class?

任何想法?

推荐答案

您想在自定义控制扩展DropDownList的......不是在用户控件。

You want to extend DropDownList in a Custom Control... not in a usercontrol.

创建一个新的类库项目叫在MyLibrary。

Create a new Class Library Project called MyLibrary.

添加类调用MyDropDownList.cs

Add a class called MyDropDownList.cs

namespace My.Namespace.Controls
{
[ToolboxData("<{0}:MyDropDownList runat=\"server\"></{0}:MyDropDownList>")]
public class MyDropDownList: DropDownList
{
    // your custom code goes here
    // e.g.
    protected override void  RenderContents(HtmlTextWriter writer)
    {
        //Your own render code
    }
}
}

在您编译库,你可以参考在Web应用程序添加到它。

Once you compile your library, you can add a reference to it in your web application.

和在你的web.config标签preFIX

And a tagprefix in your web.config

    <add tagPrefix="my" namespace="My.Namespace.Controls" assembly="MyLibrary" />

这应该允许您添加到您的ASPX / ASCX的

That should allow you to add this to your aspx/ascx's

<my:MyDropDownList ID="myDDl" runat="server">
    ...
</my:MyDropDownList>

这篇关于在ASP.NET DropDownList的子类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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