Setting ASP.NET page controls from class library assembly
-
I use model view presenter approach for ASP.NET web site. The presentation part is compiled in separate class library where view contracts and presenters are defined:
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()
}
}However after stepping out of Presenter.DisplayText() Text property of myLabel becomes null again as though no assignment were done. By all means if you replace the only line in myButton click event with direct setting of myLabel Text property everything stays assigned.
Чесноков
-
I use model view presenter approach for ASP.NET web site. The presentation part is compiled in separate class library where view contracts and presenters are defined:
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()
}
}However after stepping out of Presenter.DisplayText() Text property of myLabel becomes null again as though no assignment were done. By all means if you replace the only line in myButton click event with direct setting of myLabel Text property everything stays assigned.
Чесноков
And what is doing method Generate()?
No more Mister Nice Guy... >: |
-
And what is doing method Generate()?
No more Mister Nice Guy... >: |
returns string of letters
Чесноков
-
returns string of letters
Чесноков
I am asking because I am trying to work out something. But... huh whatever. I would say that you just setting text in another instance.
No more Mister Nice Guy... >: |