Loading Controls based on Postback event data

  • Thread starter Thread starter jones.jeremyp
  • Start date Start date
J

jones.jeremyp

Ok, I am building a control, and it is a Calendar and a previous and
next month buttons. The Calendar is build completely by hand. Now, it
is using various properties such as Month, Day, Year to build the
calendar itself. My next navigation buttons are manipulating these
properties. When the page posts back, the calendar is a month behind
what is stored in the properties. To make things more difficult, each
day is clickable, so the eventhandlers for each day needs to added
early on in the life cycle.

My question is, how can I build the calendar based on the updated
properties on postback?

Any Suggestions?

Thanks,
Jeremy
 
Because it is for a school project, and we're trying to create the
calendar as our own control. Learning experience.
 
They are LinkButtons created on the fly, and with the event added to
the delegate. Here is my loadTable method

public void loadTable()
{
this.initializeDate();
ArrayList cal=getCalendar(this.Month,this.Year);
string[] dayTitles={"Sun","Mon","Tue","Wed","Thu","Fri","Sat"};
TableRow headerRow=new TableRow();
TableCell headerCell=new TableCell();
headerCell.Text=getMonth(this.Month) + " " +this.Year;
headerCell.ColumnSpan=7;
headerCell.HorizontalAlign=HorizontalAlign.Center;
headerRow.Cells.Add(headerCell);
TableRow dayRow=new TableRow();
foreach(string s in dayTitles)
{
TableCell temp=new TableCell();
temp.Text=s;
dayRow.Cells.Add(temp);
}
Calendar.Rows.Add(headerRow);
Calendar.Rows.Add(dayRow);

for(int i=0;i<cal.Count;i++)
{
TableRow row=new TableRow();
int[] week=(int[])cal;
foreach(int d in week)
{
TableCell cell=new TableCell();
cell.HorizontalAlign=HorizontalAlign.Right;
cell.VerticalAlign=VerticalAlign.Top;
if(d!=0)
{
if(d==Day)
cell.BackColor=Color.LightGray;

LinkButton dayLink=new LinkButton();
dayLink.Text=d.ToString();
dayLink.Click +=new EventHandler(dayLink_Click);
cell.Controls.Add(dayLink);
}
else
{
cell.Controls.Add(new LiteralControl("&nbsp;"));
}
row.Cells.Add(cell);
}
Calendar.Rows.Add(row);
}
}
 
Back
Top