2012-11-03 4 views
0

.NET Framework 3.5를 사용하는 ASP .NET 프로젝트에서 작업하고 있습니다. 따라서 다른 사용자 정의 컨트롤 안에 사용자 정의 컨트롤을 캐스팅하려고합니다. 따라서 다음 코드를 사용하고 있습니다. 다른 컨트롤에서 사용자 정의 컨트롤 전송하기

<%@ Reference Control="test2.ascx" %> 

과 test.ascx.cs에

가 파일 : 다음 test.ascx 파일에

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'를 찾을 수 없습니다 (사용 지시문이나 어셈블리 참조가 누락 되었습니까?) " "

+0

왜 ASP를 배치해야합니까? 앞에? 'test2_asxc' 만 사용하려고합니까? – Aristos

답변

0

바로 할 수 없습니다. treestructure_ascxtest2_ascx 파일은 두 컨트롤을 모두 구현하는 서명 aload가있는 인터페이스에서 상속됩니다.

모두 들어
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 
    } 
} 

를 들어, 당신은 당신이 당신의 aload()에 액세스 할 수 LoadControl를 사용하여 제어 및 캐스팅 할 것이다 것

protected void Button1_Click(object sender, EventArgs e) 
{ 
    var testing = (ICustomLoader)LoadControl("test2.ascx"); 
    testing.aload(); 
} 

참고 : ASP 네임 스페이스가 필요하지 않습니다.

관련 문제