1. make sure your 服务器控件 has a namespace
2. compile the 服务器控件 cs file into a dll and copy it to the bin directory of your virtual directory
3. try something like the following in your aspx page:<%@ Register TagPrefix="my" Namespace="YourControlNamespace" Assembly="YourControlDLLNameWithoutTheExtension" %><my:YourControlClassName id="whatever" runat="server" />
2. compile the 服务器控件 cs file into a dll and copy it to the bin directory of your virtual directory
3. try something like the following in your aspx page:<%@ Register TagPrefix="my" Namespace="YourControlNamespace" Assembly="YourControlDLLNameWithoutTheExtension" %><my:YourControlClassName id="whatever" runat="server" />
解决方案 »
- DropDownList有一个无效的SelectedValue 因为它不在项目列表中,不要小看它
- VS点运行时的出错信息
- 泛型:
- “参数无效”的脚本错误
- 问个问题,怎么在Asp.net中表格中用Response.Write()(在线急等)
- 请教一个数据库查询问题
- 读取数据库中Image类型的图片,就是只显示它的类型:System.Byte[] , 不显示图片(解决马上给分)
- 如何将DropDownList和ListBox数据一起插入到数据库
- 哪里可以得到免费的SSL证书?
- 帮忙看看程序哪错了(访问access数据库)
- 在DATAGRID中加入CHECKBOX的問題??
- DataGrid更新语句到数据库出错,提示: System.Data.OracleClient.OracleException: ORA-01745: 无效的主机/赋值变量名
using System.Web.UI;
using System.Web.UI.WebControls;
using System.ComponentModel;
namespace wdfx_test
{
public class WebCustomControl1 : WebControl
{
private string text;
public string Text
{
get
{
return text;
} set
{
text = value;
}
}
protected override void Render(HtmlTextWriter output)
{
output.Write("这是第一个自一义控件");
}
}
}
引用控件的文件:CustomControl.aspx为:<%@ Register TagPrefix="CC1" Namespace="wdfx_test" Assembly="customcontrols"%>
<%@ Page language="c#" Codebehind="CustomControl.aspx.cs" AutoEventWireup="false" Inherits="wdfx_test.CustomControl" %>
<HTML>
<HEAD>
<title>CustomControl</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 id="CustomControl" method="post" runat="server">
<CC1:WebCustomControl1 runat="server" id="wc1" />
</form>
</body>
</HTML>
而且在BIN下也生成了customcontrols.dll
但运行时出现以下错误:
基类包括字段“wc1”,但其类型 (wdfx_test.WebCustomControl1) 与控件 (wdfx_test.WebCustomControl1) 的类型不兼容。源错误:
行 12: <body MS_POSITIONING="GridLayout">
行 13: <form id="CustomControl" method="post" runat="server">
行 14: <CC1:WebCustomControl1 runat="server" id="wc1" />
行 15: </form>
行 16: </body>
<HTML>
<body MS_POSITIONING="GridLayout">
<form id="CustomControl" method="post" runat="server">
<CC1:WebCustomControl1 runat="server" id="wc1" />
</form>
</body>
</HTML>