2017-05-23 76 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; 
     } 
    } 
} 
相關問題