I haven't touched ASP.NET Web Forms in years and I'm a bit rusty with it.
I currently have a user control which has a list of editable articles, this user control contains another user control (EditArticle.ascx), which is not visible on load.
EditArticle has a property called Article which reflects the article one could edit.
However when I'm triggering a link click and passing an article to EditArticle's Article property and make it visible, EditArticle's Page_Load method triggers a null reference exception when it tries to access the Article property. So Page_Load is probably called before the property is set?
So I've added something like this to the property setter:
public NewsArticle Article
{
get { return _article; }
set { _article = value;
BindValues();}
}
protected void BindValues()
{
ArticleTitle.Text = Article.Title;
ArticleSummary.Text = Article.Lead;
TextEditor.Text = Article.Article;
}
And it works like this, the text boxes are filled with the appropriate data when the EditArticle control is shown.
What would be the correct and appropriate way to do this?