使用复合控件-(初次使用的怪现象)

在我开始学习编写复合控件时,发现了这样一个怪现象,不知大家有没有遇到。

我按照网上的写了一个登陆的控件,代码是一样的,只是命名空间不同,


错误是那一个是在Namespace="ClassLibrary1.LoginControls"在命名空间下的,而正确显示的是在
Namespace="CustomComponents"空间下的,但两个控件的内部代码是一样的。

<%@ Register Assembly="ClassLibrary1" Namespace="ClassLibrary1.LoginControls" TagPrefix="cc1" %>

<%@ Register Assembly="ClassLibrary1" Namespace="CustomComponents" TagPrefix="cc2" %>

 

 <cc2:CompositeLogin ID="CompositeLogin2" runat="server" NameLabel="姓名: "
                PasswordLabel
="密码: " BackColor="IndianRed" BorderColor="Gray" BorderWidth="1px"
                NameErrorMessage
="你必须输入姓名" PasswordErrorMessage="dd" Name="fff"/>
        
<cc1:dgwLoginControl ID="DgwLoginControl1" runat="server" NameLabel="姓名: "
                PasswordLabel
="密码: " BackColor="IndianRed" BorderColor="Gray" BorderWidth="1px"
                NameErrorMessage
="你必须输入姓名" PasswordErrorMessage="dd" Name="fff"/>

好了,,在设计界面上控件出错了,但在网页又好何呢,?看看图片就知了

结果是正常显示了。

好!!!那我把Namespace="ClassLibrary1.LoginControls"这一个命名空间改为Namespace="ClassLibrary1"结果,如我所想的,全部都可以正常显示。这难道是一个BUG??????请指教。
还有一点要注意的,那就是设置属性名称的时候最好不要与对象名相同
如:[BrowsableAttribute(true)]
        [DescriptionAttribute("表水平对齐")]
        [CategoryAttribute("Appearance")]
        public virtual HorizontalAlign HorizontalAlign
        {
            get { return ((CustomTableStyle)ControlStyle).; }
            set { ((CustomTableStyle)ControlStyle).HorizontalAlign = value; }
        }

在这里我设置了公开的属性名称为HorizontalAlign而TableStyle的方法中有一个HorizontalAlign的对象。如果这样公开属性的话,有可能导致在设计界面时控件出错提示为不能对HorizontalAlign属性进行赋值或刷新控件时不能保存刚刚修改的数据。
我们应该写成这样的:[BrowsableAttribute(true)]
        [DescriptionAttribute("表水平对齐")]
        [CategoryAttribute("Appearance")]
        public virtual HorizontalAlign HorizontalAlignX
        {
            get { return ((CustomTableStyle)ControlStyle).; }
            set { ((CustomTableStyle)ControlStyle).HorizontalAlign = value; }
        }
确保公开属性名称与基本的对象名不相同

posted on 2008-01-11 20:16  笨雀  阅读(217)  评论(0编辑  收藏  举报