我正在使用.NET framework 3.5开发ASP .NET项目。我试图在另一个用户控件内部转换用户控件,因此我使用以下代码。
test.ascx文件中的:
<%@ Reference Control="test2.ascx" %>
并在test.ascx.cs文件中:
private ASP.test2_ascx testing;
protected void Button1_Click(object sender, EventArgs e)
{
testing = (ASP.treestructure_ascx)LoadControl("test2.ascx");
testing.aload();
问题是“ASP”这个词有下划线说“Error17”找不到类型或命名空间名称'ASP'(你是否缺少using指令或程序集引用?)“ “
答案 0 :(得分:0)
你不能马上做到这一点。使treestructure_ascx
和test2_ascx
文件从具有实现两个控件的签名副本的接口继承。
public interface ICustomLoader
{
public void aload();
}
对于两个控件:
public class treestructure_ascx : UserControl, ICustomLoader
{
public void aload()
{
//your loading codes goes here
}
}
和test2_ascx
public class test2_ascx : UserControl, ICustomLoader
{
public void aload()
{
//your loading codes goes here
}
}
因此,您可以投射控件并使用LoadControl
,您就可以访问aload()
protected void Button1_Click(object sender, EventArgs e)
{
var testing = (ICustomLoader)LoadControl("test2.ascx");
testing.aload();
}
注意:我猜您不需要ASP
命名空间。