Click here to Skip to main content
15,887,214 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
Hi,

I have a user control that returns search results and adds them to an asp table. The results include dates. I have another user control that displays dates in a nice "calendar date" style.

The results control works fine without the date controls.

I instantiate the date control like this:
C#
CalenderDate date = new CalenderDate();
date.InitializeAsUserControl(Page);
cell = new TableCell();
date.Date = Result.Date1;
cell.Controls.Add(date);
row.Cells.Add(cell);

date = new CalenderDate();
date.InitializeAsUserControl(Page);
cell = new TableCell();
date.Date = result.Date2;
cell.Controls.Add(date);
row.Cells.Add(cell);


The date property looks like this:
C#
public partial class CalenderDate : System.Web.UI.UserControl
{
    public DateTime _date;

    public DateTime Date
    {
        get
        {
            return _date;
        }
        set
        {
            _date = value;
            litMonth.Text = _date.ToString("MMM");
            litDayOfWeek.Text = _date.ToString("dddd");
            litDayOfMonth.Text = _date.ToString("dd");
            litTime.Text = _date.ToString("HH:mm");
        }
    }
}


My error is that litMonth is null. I though that date.InitializeAsUserControl(Page); would solve this?

So where am I going wrong?

Thanks ^_^
Andy
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900