Settings a webusercontrol object's property
-
I'm trying to add a webusercontrol I've created dynamically through a page. I have the properties all set up correctly, and those are working. What happens when the Page_Load is that the labels that I have in the control are still null when the Page_Load runs, so a NullReferenceNotHandled exception is thrown when I try to access a label's Text property. What am I doing wrong? Maybe I'm using the webusercontrol in the wrong way, I'm used to writing desktop applications... He's the code I'm using, assume that I have the correct code for the properties
public NewsPost(string title, string date, string message, int newsId) { this.Title = title; this.Date = date; this.Message = message; this.NewsId = newsId; } protected void Page\_Load(object sender, EventArgs e) { lblTitle.Text = Title; //NullReferenceNotHandled error is thrown here lblDate.Text = Date; lblMessage.Text = Message; }
-
I'm trying to add a webusercontrol I've created dynamically through a page. I have the properties all set up correctly, and those are working. What happens when the Page_Load is that the labels that I have in the control are still null when the Page_Load runs, so a NullReferenceNotHandled exception is thrown when I try to access a label's Text property. What am I doing wrong? Maybe I'm using the webusercontrol in the wrong way, I'm used to writing desktop applications... He's the code I'm using, assume that I have the correct code for the properties
public NewsPost(string title, string date, string message, int newsId) { this.Title = title; this.Date = date; this.Message = message; this.NewsId = newsId; } protected void Page\_Load(object sender, EventArgs e) { lblTitle.Text = Title; //NullReferenceNotHandled error is thrown here lblDate.Text = Date; lblMessage.Text = Message; }
Dynamically adding controls is always grief. A better way to do it is to build a collection of news item object and then bind them to a data driven control, in order to shoe them.
Christian Graus Driven to the arms of OSX by Vista.