2017-05-23 44 views

回答

0

这将没有多大意义,从自定义控件外界补充的依赖。

创建一个包含您所指定的属性的接口:

public interface IMyPageInterface 
{ 
    string MyProperty {get;set;} 
} 

实现你的页面上的接口:

//your page code behind 
public partial class WebForm1: System.Web.UI.Page,IMyPageInterface 
{ 
    public string MyProperty 
    { 
     get; 
     set; 
    } 
} 

,你可以得到你的页面IMyPageInterface在您的自定义控制

IMyPageInterface myPage = this.Page as IMyPageInterface; 
myPage.MyProp... 

也可以定义IMyPageInterface类型的属性

public class MyControl :Control 
{ 
    public IMyPageInterface MyPage 
    { 
     get 
     { 
      return this.Page as IMyPageInterface; 
     } 
    } 
} 
相关问题