我用这样的事件创建了一个用户控件:
public partial class Person : System.Web.UI.UserControl
{
public delegate void EditPersonHandler(object sender, EditPersonEventArgs e);
public event EditPersonHandler EditPerson;
protected void Page_Load(object sender, EventArgs e)
{
}
}
这是我的 EditPersonEventArgs :
public class EditPersonEventArgs:EventArgs
{
private int id;
public int ID
{
get { return id; }
set { id = value; }
}
public EditPersonEventArgs(int ID)
{
id = ID;
}
}
现在我想将此用户控件添加到我的页面,我这样做:
<%@ Register TagPrefix="UControl" TagName="UControlPerson" Src="~/SimpleUC/Person.ascx" %>
<div>
<UControl:UControlPerson ID="UControlPerson" runat="server"
OnEditPerson="UControlPerson_EditPerson" />
</div>
这是我处理 OnSavePerson
的函数:
protected void UControlPerson_EditPerson(object sender, EditPersonEventArgs e)
{
}
我构建了解决方案。 但是当我呈现页面时出现此错误:
Description: An error occurred during the compilation of a resource required to service this
request. Please review the following specific error details and modify your source code
appropriately.
Compiler Error Message: CS0426: The type name 'SimpleUC' does not exist in the type
'System.Web.UI.UserControl'
这是我的命名空间:
命名空间 UserControl.SimpleUC
最佳答案
您有命名空间冲突,您的用户控件命名空间 UserControl.SimpleUC
的 UserControl
部分被解析为命名空间 System.Web.UI。用户控件
。
解决此问题的最简单方法是为您的控件选择另一个命名空间。可能类似于 UserControls.SimpleUC
关于c# - 将用户控件添加到 asp.net 页面,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10863081/