自定义控件有一个自定义属性。
希望实现该属性的可枚举设计器。
在设计时已经实现,并且看到的效果也是想要的效果。并在在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>
希望实现该属性的可枚举设计器。
在设计时已经实现,并且看到的效果也是想要的效果。并在在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>
解决方案 »
- 新手python问题
- 获取属性值
- vss2005和vs2005的搭配问题
- 又写一篇傻瓜文章,如果知道的就不用看了:asp.net2.0自定义控件开发---鼠标移到按钮上更改背景颜色,移出后恢复
- DropDownList问题!(70分)
- 控件的嵌套
- 请问GridView排序后更新的问题
- 请教数据库设计的问题
- 如何在自定义控件中加入datagrid?我加了怎么不显示?
- 我在javascript中写了个for循环来做长时间的业务处理,同时把处理进度写到页面上的文本框中,奇怪的是文本框的内容直到循环结束才会显示
- 操作Excel的问题
- 我有一个ASPX页面要定制SINA的新闻,地址在这里:http://rss.sina.com.cn/my_sina_web_rss_news.html?url=news/allnews/sports.xml
分析器错误
说明: 在分析向此请求提供服务所需资源时出错。请检查下列特定分析错误详细信息并适当地修改源文件。 分析器错误消息: 无法为“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
==================================================================================================
([email protected])