设置自定义控件属性

时间:2010-04-20 20:24:27

标签: c# asp.net user-controls

我虽然很简单,但我今天无法得到它。

我有一个用户控件,其中包含一个网格控件。

public Unit Width
{
    get
    {
        return CustomerGrid.Width;
    }
    set
    {
        CustomerGrid.Width = value;

    }
}

我公开了width属性,当我在设计器中设置它时,它在运行时工作,但不是设计时。

我将继承哪个类或重写方法以使我的控件在设计时运行。

注意我尝试从WebControl继承但得到了消息

Make sure that the class defined in this code file matches the 'inherits' attribute, and that it extends the correct base class 

1 个答案:

答案 0 :(得分:5)

我知道你在谈论用户控件(ascx)而不是自定义控件(没有ascx)。如果是这种情况,您应该从UserControl继承,并且您可以在设计时使用该属性而无需任何其他添加。

如果你对自定义控件有所了解,那么你有一篇关于为自定义控件添加设计时支持的好文章

http://msdn.microsoft.com/en-us/library/aa478960.aspx