簡體   English   中英

從類庫程序集設置ASP.NET頁面控件

[英]Setting ASP.NET page controls from class library assembly

我對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()     
    }        
}

但是,退出Presenter.DisplayText()myLabel Text屬性再次變為null,好像沒有完成分配。 如果您用myLabel Text屬性的直接設置替換了myButton click事件中的唯一行,則一切將保持分配狀態。

Generate方法是否返回非空字符串? 在這種情況下,這似乎是唯一的罪魁禍首。 它也可以解釋為什么設置myLabel直接起作用。

為了進行診斷, View.DisplayText文字字符串傳遞給View.DisplayText而不是調用Generate

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM