2012-06-02 54 views
2

我创建这样一个事件的用户控件:用户控件添加到asp.net页面

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' 

这是我的名字空间: namespace UserControl.SimpleUC

回答

1

你有一个命名空间冲突,您的用户控件命名空间的UserControl部分UserControl.SimpleUC被解析为名字空间System.Web.UI.UserControl

解决此问题的最简单方法是为控件选择另一个名称空间。可能类似UserControls.SimpleUC

相关问题