为什么我的自定义控件调用时总是类型不兼容呢?(附原码)

bluesky1975 2002-05-27 06:32:17
“/agent”应用程序中的服务器错误。
--------------------------------------------------------------------------------

分析器错误
说明: 在分析向此请求提供服务所需资源时出错。请检查下列特定分析错误详细信息并适当地修改源文件。

分析器错误信息: 基类包括字段“CustomControl1”,但其类型 (CustomControl.CustomControl) 与控件 (CustomControl.CustomControl) 的类型不兼容。

源错误:


行 12: <body MS_POSITIONING="GridLayout">
行 13: <form>
行 14: <cc1:CustomControl id="CustomControl1" strDataBase="operator" strName="operator_name" strNo="operator_no" runat="server"></cc1:CustomControl>
行 15: </form>
行 16: </body>


源文件: http://localhost/agent/test.aspx 行: 14


--------------------------------------------------------------------------------
版本信息: Microsoft .NET 框架版本:1.0.3705.0; ASP.NET 版本:1.0.3705.0


自定义控件myDownList:
--------------------------------------------------------------------------------
using System;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.IO;

namespace CustomControl
{
/// <summary>
/// CustomControl 的摘要说明。
/// </summary>
public class CustomControl : System.Web.UI.WebControls.WebControl,INamingContainer
{
private string _strDataBase,_strName,_strNo;

public string strDataBase
{
get{return _strDataBase;}
set{_strDataBase = value;}
}
public string strName
{
get{return _strName;}
set{_strName = value;}
}
public string strNo
{
get{return _strNo;}
set{_strNo = value;}
}

protected override void CreateChildControls()
{
StreamReader sr = new StreamReader("c:\\inetpub\\wwwroot\\agent\\Config.txt");
string DBServer = sr.ReadLine();
string DBDataBase = sr.ReadLine();
sr.Close();
SqlConnection myConnection = new SqlConnection("server="+ DBServer +";uid=sa;pwd=;database=" + DBDataBase + ";");
SqlDataAdapter myCommand = new SqlDataAdapter("select "+_strName+","+_strNo+" from "+_strDataBase,myConnection);
DataSet myDataSet = new DataSet();
myCommand.Fill(myDataSet,"myTable");

ListBox myListBox = new ListBox();
myListBox.DataSource = myDataSet;
myListBox.DataTextField = _strName;
myListBox.DataValueField = _strNo;
myListBox.DataBind();
Controls.Add(myListBox);

Controls.Add(new LiteralControl("请选择"));
}
}
}
--------------------------------------------------------------------------------

网页文件:test.aspx
--------------------------------------------------------------------------------
<%@ Page language="c#" Codebehind="test.aspx.cs" AutoEventWireup="false" Inherits="agent.test" %>
<%@ Register TagPrefix="cc1" Namespace="CustomControl" Assembly="myListBox" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<HTML>
<HEAD>
<title>test</title>
<meta name="GENERATOR" Content="Microsoft Visual Studio 7.0">
<meta name="CODE_LANGUAGE" Content="C#">
<meta name="vs_defaultClientScript" content="JavaScript">
<meta name="vs_targetSchema" content="http://schemas.microsoft.com/intellisense/ie5">
</HEAD>
<body MS_POSITIONING="GridLayout">
<form>
<cc1:CustomControl id="CustomControl1" strDataBase="operator" strName="operator_name" strNo="operator_no" runat="server"></cc1:CustomControl>
</form>
</body>
</HTML>
--------------------------------------------------------------------------------

...全文
99 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
juqiang 2002-05-28
  • 打赏
  • 举报
回复
我是昨天晚上第一个回答的,为什么看帖子的列表,日期是今天早上?(只有我一个回帖)难道显示时间由更新时间改为了浏览时间?
juqiang 2002-05-28
  • 打赏
  • 举报
回复
你的namespace和保留字(?)重复了!反正,把这个名字改掉就可以了!
juqiang 2002-05-27
  • 打赏
  • 举报
回复
修改你的namespace,不要叫CustomControl!!!改成任何一个名字都可以!!!然后编译就可以了!
否则会提示错误!嗬嗬,给分啊!

62,074

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

试试用AI创作助手写篇文章吧