To create a project in the past few days, You need to display the calendar for two months at the same time on one page. When one calendar changes the month, the other also needs to synchronize the changes.
The solution is to add two calendar controls to a page, and then update the visibledate attribute of another calendar in the onvisiblemonthchanged event of the calendar ar. The Code is as follows:
ASPX page 1 <asp: Calendar id = "calendar1" runat = "server" Height = "236px" onvisiblemonthchanged = "calendar#visiblemonthchanged"
2 width = "273px"> </ASP: Calendar>
3 <asp: Calendar id = "calendar2" runat = "server" Height = "195px" width = "271px" onvisiblemonthchanged = "calendar2_visiblemonthchanged">
4 </ASP: Calendar>
CS page 1 protected void page_load (Object sender, eventargs E)
2 {
3 if (! Ispostback)
4 {
5 // when loading the page for the first time, you need to update the calendar control of the next month to display the month as the next month
6 This. calendar2.visibledate = datetime. Now. addmonths (1 );
7}
8}
9
10 protected void calendar#visiblemonthchanged (Object sender, monthchangedeventargs E)
11 {
12 // set the time of the second calendar control to the next month of the new time of the first calendar Control
13 This. calendar2.visibledate = E. newdate. addmonths (1 );
14}
15
16 protected void calendar2_visiblemonthchanged (Object sender, monthchangedeventargs E)
17 {
18 // set the time of the first calendar control to the previous month of the new time of the second calendar Control
19 this. calendar1.visibledate = E. newdate. addmonths (-1 );
20}
21
22