Loading Controls based on Postback event data

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
 
J

Jeremy Jones

Because it is for a school project, and we're trying to create the
calendar as our own control. Learning experience.
 
J

Jeremy Jones

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);
}
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,901
Latest member
Noble71S45

Latest Threads

Top