2012-10-09 69 views
0

我使用ASP.NET網站的模型視圖演示程序方法。呈現部分在單獨的類庫編譯其中視圖合同和主持人的定義:從類庫彙編中設置ASP.NET頁面控件

MyPresentation assembly 
IMyView 
{ 
    DisplayText(string text); 
} 
MyPresenter 
{ 
    public IMyView View { get; set; } 
    public DisplayText() 
    { 
     string text = Generate(); 
     View.DisplayText(text); 
    } 
} 

MyWebApplication assembly 
public partial class MyForm : System.Web.UI.Page, IMyView 
{ 
    public void DisplayText(string text) 
    { 
     this.myLabel.Text = text; 
    } 
    ... 
    protected void myButton_Click(object sender, EventArgs e) 
    { 
     Presenter.DisplayText(); // calls this.DisplayText()  
    }   
} 

然而走出的myLabelPresenter.DisplayText() Text屬性後,再次成爲空,就像沒有分配中進行。通過所有方法,如果您替換myButton單擊事件中的唯一行,並直接設置myLabel文本屬性將保持分配狀態。

回答

1

Generate方法是否返回一個非空字符串?這看起來像是這個案件中唯一的罪魁禍首。這也可以解釋爲什麼設置myLabel直接起作用。

要診斷,請將文字字符串傳遞到View.DisplayText而不是調用Generate

+0

否它不,我已經從主持人 –

+0

返回一個已知字符串「但是,在退出Presenter.DisplayText()之後myLabel的Text屬性再次變爲空」 –

相關問題