从自定义用户控件基类派生用户控件 - >名称空间错误 [英] Derive user control from custom user control base class --> namespace error?
问题描述
亲爱的,
我遇到了这个问题:在VS 2012中我创建了这个基本的用户控件,派生自System.Web.UI.UserControl:
文件test.ascx.cs:
使用系统;
使用 System.Collections.Generic;
使用 System.Linq;
使用 System.Web;
使用 System.Web.UI;
使用 System.Web.UI.WebControls;
命名空间 B2CInterface.UC
{
public partial class UC_Base_test:System.Web.UI.UserControl
{
protected void Page_Load( object sender,EventArgs e)
{
int a = 1 ; // 这里的一些代码...
}
}
}
和相应的test.ascx:
<%@ 控制 语言 = C# AutoEventWireup = true CodeFile = test.ascx.cs 继承 = B2CInterface.UC.UC_ Base_test %>
< p > test < ; / p >
现在,我有第二个用户控件应该派生自第一个用户控件(UC_Base_test):
文件test2.ascx.cs:
使用系统;
使用 System.Collections.Generic;
使用 System.Linq;
使用 System.Web;
使用 System.Web.UI;
使用 System.Web.UI.WebControls;
命名空间 B2CInterface.UC
{
public partial class UC_Base_test2:UC_Base_test // < span class =code-comment> System.Web.UI.UserControl
{
protected void Page_Load( object sender,EventArgs e)
{
// 此处的其他代码...
}
}
}
和相应的test2.ascx:
<%@ 控制 语言 = C# AutoEventWireup = true CodeFile = test2.ascx.cs 继承 = B2CInterface.UC.UC_Base_test2 %>
现在,当我编译时,我收到此错误:
错误 12 类型或命名空间名称' UC_Base_test'(你是否错过使用指令或程序集引用?)C:\Progetti \B2CInterface\UC\Base \ test2.ascx.cs 10 42 B2CInterface
谢谢提前任何人都能解决这个问题!!
PJ
请使用@来表示用户控制参考
假设控件(.ascx文件)放在Controls文件夹中。
<%@ Page 语言 = C# %> ;
<%@ 参考 控制 = 〜/ Controls / UC_Base_test.ascx %> 跨度>
Dear all,
I''m stuck with this problem: in VS 2012 I''ve created this basic User Control, derived from System.Web.UI.UserControl:
File test.ascx.cs:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace B2CInterface.UC
{
public partial class UC_Base_test : System.Web.UI.UserControl
{
protected void Page_Load(object sender, EventArgs e)
{
int a = 1; // some code here...
}
}
}
and the corresponding test.ascx:
<%@ Control Language="C#" AutoEventWireup="true" CodeFile="test.ascx.cs" Inherits="B2CInterface.UC.UC_Base_test" %>
<p>test</p>
Now, I''ve a second User Control that should be derived from the first one (UC_Base_test):
File test2.ascx.cs:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace B2CInterface.UC
{
public partial class UC_Base_test2 : UC_Base_test // System.Web.UI.UserControl
{
protected void Page_Load(object sender, EventArgs e)
{
//other code here...
}
}
}
and the corresponding test2.ascx:
<%@ Control Language="C#" AutoEventWireup="true" CodeFile="test2.ascx.cs" Inherits="B2CInterface.UC.UC_Base_test2" %>
Now, when I compile I get this error:
Error 12 The type or namespace name 'UC_Base_test' could not be found (are you missing a using directive or an assembly reference?) C:\Progetti\B2CInterface\UC\Base\test2.ascx.cs 10 42 B2CInterface
I thank in advance anyone who will be able to solve this!!
PJ
Please sepicify user control using@Reference
Assuming the control(.ascx file) is placed in Controls folder.
<%@ Page Language="C#" %> <%@ Reference Control="~/Controls/UC_Base_test.ascx" %>
这篇关于从自定义用户控件基类派生用户控件 - >名称空间错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!