为什么我的自定义控件调用时总是类型不兼容呢?(附原码)
“/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>
--------------------------------------------------------------------------------