自定义控件有一个自定义属性。
希望实现该属性的可枚举设计器。
在设计时已经实现,并且看到的效果也是想要的效果。并在在IDE中控件也像我希望的那样展开了。(3个C#类在一个项目中,aspx在另一个项目中。)
但是我Run的时候,出现以下的“黄页”:分析器错误 
说明: 在分析向此请求提供服务所需资源时出错。请检查下列特定分析错误详细信息并适当地修改源文件。 分析器错误消息: 无法为“ZSoft.Platform.Web.UI.BizCodeTextType”类型的值生成代码。试图为 BizCodeTextType 生成属性值时出现此错误。源错误: 行 1: <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="ZPageTest.aspx.cs" Inherits="ZSoft.Platform.Web.UI.Test.ZPageTest" %>
行 2: 
行 3: <%@ Register Assembly="ZSoft.Platform.Web" Namespace="ZSoft.Platform.Web.UI.Controls" 源文件: /UI/ZPageTest.aspx    行: 1 namespace Haoze.Web.UI.Controls
{
    [TypeConverter( typeof( MyTypeConverter ))]
    public class MyType
    {
        public MyType()
        {
        }        public Type Type
        {
            get;
            set;
        }        public override string ToString()
        {
            return Type == null ? string.Empty : Type.Name;
        }
    }
}
namespace Haoze.Web.UI.Controls
{
    public class MyTypeConverter : TypeConverter
    {
        static List<Type> m_Types = new List<Type>();        static MyTypeConverter()
        {
            m_Types.Clear();
            Assembly[] assembies = AppDomain.CurrentDomain.GetAssemblies();
            foreach (Assembly assembly in assembies)
            {
                if (assembly.FullName.IndexOf("Haoze.Web.UI.Controls") < 0) continue;
                foreach (Type type in assembly.GetTypes())
                {
                    m_Types.Add(type);
                }
            }
        }        public override bool CanConvertFrom(ITypeDescriptorContext context, Type sourceType)
        {
            return sourceType == typeof(string);
        }        public override object ConvertFrom(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value)
        {
            string sValue = value as string;
            if (sValue != null)
            {
                foreach (Type type in m_Types)
                {
                    if (type.FullName.IndexOf(sValue) >= 0)
                    {
                        return new MyType()
                        {
                            Type = type
                        };
                    }
                }
                return null;
            }
            return null;
        }        public override bool GetStandardValuesSupported(ITypeDescriptorContext context)
        {
            return true;
        }        public override StandardValuesCollection GetStandardValues(ITypeDescriptorContext context)
        {
            return new StandardValuesCollection(m_Types);
        }
    }
}
namespace Haoze.Web.UI.Controls
{
    [DefaultProperty("Text")]
    [ToolboxData("<{0}:MyControl runat=server></{0}:MyControl>")]
    public class MyControl : WebControl
    {
        [TypeConverter(typeof(MyTypeConverter))]
        public MyType Type
        {
            get;
            set;
        }        protected override void RenderContents(HtmlTextWriter output)
        {
            output.RenderBeginTag(HtmlTextWriterTag.Span);
            output.Write("Type is:"); 
            if (Type != null && Type.Type != null)
            {
                output.Write(Type.Type.AssemblyQualifiedName);
            }
            output.RenderEndTag();
        }
    }
}
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="Haoze.Web.UI.Controls.Test.WebForm1" %><%@ Register assembly="Haoze.Web.UI.Controls" namespace="Haoze.Web.UI.Controls" tagprefix="cc1" %><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>无标题页</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        
        <cc1:MyControl ID="MyControl1" runat="server" Type="MyType" />
        
    </div>
    </form>
</body>
</html>

解决方案 »

  1.   

    ZSoft.Platform.Web.UI.BizCodeTextType是你自定义的?
      

  2.   

    我贴错错误信息了,对不起大家。错误信息是这个:==============================================================================================
    分析器错误 
    说明: 在分析向此请求提供服务所需资源时出错。请检查下列特定分析错误详细信息并适当地修改源文件。 分析器错误消息: 无法为“Haoze.Web.UI.Controls.MyType”类型的值生成代码。试图为 Type 生成属性值时出现此错误。源错误: 
    行 1:  <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="Haoze.Web.UI.Controls.Test.WebForm1" %>
    行 2:  
    行 3:  <%@ Register assembly="Haoze.Web.UI.Controls" namespace="Haoze.Web.UI.Controls" tagprefix="cc1" %>
     源文件: /WebForm1.aspx    行: 1 
    ==================================================================================================
      

  3.   

    我也是遇到这样的问题, 怎么还没有人解决?
    ([email protected])