How to Make Microsoft's calendar control display a two-month calendar at the same time

Source: Internet
Author: User
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


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.