web 2.0

How to show and select month/year in Calendar Extender

In this post I will explain you, How to make calendar extender control to show month / year view by default and instead of selecting dates how can we use calendar extender to select months.

Before I start, let me say that I got extensive support from this forum post http://forums.asp.net/t/1349086.aspx. Thanks to Zhi-Qiang Ni, but the way he follow was a little bit lengthy. However, all credit still goes to him because I gain the exact idea from his post.

Let me start by creating a calendar extender control and attach it to a textbox.

<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<cc1:CalendarExtender ID="TextBox1_CalendarExtender" runat="server" OnClientHidden="onCalendarHidden"  OnClientShown="onCalendarShown" BehaviorID="calendar1"
    Enabled="True" TargetControlID="TextBox1">
</cc1:CalendarExtender>


Now, in extender markup, notice onClientHidden and OnClientShown event which I implemented as below.

function onCalendarShown() {
 
     var cal = $find("calendar1");
     //Setting the default mode to month
     cal._switchMode("months", true);
     
     //Iterate every month Item and attach click event to it
     if (cal._monthsBody) {
         for (var i = 0; i < cal._monthsBody.rows.length; i++) {
             var row = cal._monthsBody.rows[i];
             for (var j = 0; j < row.cells.length; j++) {
                 Sys.UI.DomEvent.addHandler(row.cells[j].firstChild, "click", call);
             }
         }
     }
 }
 
 function onCalendarHidden() 
 {
     var cal = $find("calendar1");
     //Iterate every month Item and remove click event from it
       if (cal._monthsBody) {
         for (var i = 0; i < cal._monthsBody.rows.length; i++) {
             var row = cal._monthsBody.rows[i];
             for (var j = 0; j < row.cells.length; j++) {
                 Sys.UI.DomEvent.removeHandler(row.cells[j].firstChild,"click",call);
             }
         }
     }
 
 }

Pretty simple, In onCalendarShown method I just set the default mode to month and then iterate the control to get month item and attach on click event to it. So that, it will not go further to show us dates of that month and select the first day of that month instead.

Where as, In onCalendarHidden I am simply detaching the click event from month items. Now notice the last parameter of Sys.UI.DomEvent.addHandler function, it is the name of the function which will do the rest of the magic as below.

function call(eventElement)
        {
            var target = eventElement.target;
            switch (target.mode) {
            case "month":
                var cal = $find("calendar1");
                cal._visibleDate = target.date;
                cal.set_selectedDate(target.date);
                cal._switchMonth(target.date);
                cal._blur.post(true);
                cal.raiseDateSelectionChanged();
                break;
            }
        }

Here we are simply selecting the month as the selected date of calendar control. and finally the control will look like as below.

cal_extender

You can get the source code from here :
http://cid-cdbfe38dc780f729.skydrive.live.com/self.aspx/.Public/Calendar%20Extender%20Month.zip

Comments

Mia , on 6/17/2009 4:20:32 AM Said:

Mia

Good post. Very useful. I have managed to implement this month view on one calendar extender but need it to be implemented on multiple calender extenders. Is it possible to change the javascript methods in order to use it across multiple calender extenders.

red Thailand, on 7/10/2009 1:20:28 PM Said:

red

How about  2 calendars on page. What should to modify in script.

Thanks sir.

anxiety treatment Netherlands, on 7/11/2009 1:53:09 AM Said:

anxiety treatment

Excuse me guys, I have a short difficulty... I make out u are using blogengine from microsoft. I'm running an anxiety and panic disorder blog on wordpress and i am willing to switch. Do i need a linux server for it?? Thanks, Debra Trotter

aghausman United States, on 7/12/2009 7:25:48 PM Said:

aghausman

@anxiety treatment
Though, its not the right place to ask this question. but let me answer, there is no need for linux server and BlogEngine is an open source product not by Microsoft.
Here is the URL : http://www.dotnetblogengine.net/

Agha Usman Islamic Republic of Pakistan, on 7/19/2009 7:51:15 PM Said:

Agha Usman

@Mia
of course we can do that. I guess we can modify the existing extender to create one for us. I have note your request and as soon as I get some time will write one for you.
@Red
for calendar two <cc1:CalendarExtender ID="TextBox1_CalendarExtender" runat="server" OnClientHidden="onCalendarHidden"  OnClientShown="onCalendarShown" BehaviorID="calendar2"

    Enabled="True" TargetControlID="TextBox2">
and onCalendarHidden implementation repeat the whole code for $find("calendar2")

Biss Lee Brazil, on 8/2/2009 5:59:30 PM Said:

Biss Lee

Hi,

I found the same problem. I tried modify the script passing parameters, but seemed all functions that didn't like parameters.
Did you find an answer to this problem?

Thank you

Biss

Terry Malaysia, on 8/25/2009 11:33:45 PM Said:

Terry

Hi,

How to just show year without month?

Thanks.

Zhi-Qiang Ni People's Republic of China, on 9/17/2009 9:13:18 AM Said:

Zhi-Qiang Ni

Good Sample!

Ing United States, on 9/19/2009 3:20:36 PM Said:

Ing

Cool website!! Thanks for info!!!

blogger United Kingdom, on 9/30/2009 2:08:24 PM Said:

blogger

Pleased I came across this how to entry.  How to show and select monthyear in Calendar Extender  - I have been looking for opinions on how to take on this at the present moment  and got drawn in by the title of the item in a search engine.  Reading text books and journals has not been advantageous but a few web searches has produced a resolution which should help me greatly.  Could we get by without the web.  Thanks, I will use the info and must keep your web site as a reference.

Home Repair Grant United States, on 11/1/2009 11:51:20 PM Said:

Home Repair Grant

I personally have embraced the new technologies and the CMS platforms, I think the new tools only make the web designs better. I am glad that new technologies are coming out in web design that make things easier, improved, and better looking for design.

home security camera system United States, on 11/2/2009 12:11:00 AM Said:

home security camera system

Keep 'em coming... you all do such a great job at such Concepts... can't tell you how much I, for one appreciate all you do!

Reverse Phone Lookup United States, on 11/3/2009 11:14:52 PM Said:

Reverse Phone Lookup

Hi webmaster, commenters and everybody else !!! The blog was absolutely fantastic! Lots of great information and inspiration, both of which we all need!b Keep 'em coming... you all do such a great job at such Concepts... can't tell you how much I, for one appreciate all you do!

Christmas Puzzle United States, on 11/6/2009 5:27:25 AM Said:

Christmas Puzzle

That is some inspirational stuff. Never knew that opinions could be this varied. Thanks for all the enthusiasm to offer such helpful information here.

Rocket Japanese United States, on 11/13/2009 10:20:16 PM Said:

Rocket Japanese

I am not much of a guy who thinks in so deeply about web design but I think your post had some valid points in it. Like designers are forced to design stuff within the limited code available and not go beyond it, their innovation is somewhat limited but still I think Web Design won't die! I agree that Amazon and other some big sites won't have a blog but now a days it's very important to have some sort of option available so people can quickly communicate their thoughts. I think Amazon if wants to shift it to that, they can get a customized CMS for themselves.

Currency Converter United States, on 11/13/2009 10:48:48 PM Said:

Currency Converter

I am not much of a guy who thinks in so deeply about web design but I think your post had some valid points in it. Like designers are forced to design stuff within the limited code available and not go beyond it, their innovation is somewhat limited but still I think Web Design won't die! I agree that Amazon and other some big sites won't have a blog but now a days it's very important to have some sort of option available so people can quickly communicate their thoughts. I think Amazon if wants to shift it to that, they can get a customized CMS for themselves.

jenifer United States, on 11/14/2009 10:09:47 PM Said:

jenifer

thanks a lot

Coppell homes for sale United States, on 11/15/2009 6:34:52 AM Said:

Coppell homes for sale

This article gives the light in which we can observe the reality. this is very nice one and gives indepth information. thanks for this nice article

Binary Options United States, on 11/19/2009 9:03:29 AM Said:

Binary Options

Dude.. I am not much into reading, but somehow I got to read lots of articles on your blog. Its amazing how interesting it is for me to visit you very often.

Prada Eyeglasses United States, on 11/25/2009 8:38:45 PM Said:

Prada Eyeglasses

We need to follow certain rules and regulations to avoid these kind of situations, thanks.

Acai Berry Scam United States, on 11/28/2009 5:29:47 AM Said:

Acai Berry Scam

Pretty Interesting post. Couldnt be written any better. Thanks for sharing!

cheap car insurance United States, on 12/1/2009 12:41:47 PM Said:

cheap car insurance

I wanted to thank you for this great read, pretty Interesting post. Could not be written any better. Thanks for sharing!

car insurance comparison United States, on 12/1/2009 12:45:42 PM Said:

car insurance comparison

It proved to be Very helpful to me and I am sure to all the people here! It's always nice when you can not only be informed, and healthy foods The blog was absolutely fantastic! Lots of great information and inspiration, both of which we all need!

rain boots Netherlands, on 12/4/2009 3:04:23 AM Said:

rain boots

Hi There, It seem this blog doesnt show befittingly in ie8.

garage door remote Netherlands, on 12/4/2009 3:27:11 AM Said:

garage door remote

Good Afternoon, It im sure this website does not viewed fitly in google chrome.

Edible Fruit Netherlands, on 12/4/2009 4:02:08 AM Said:

Edible Fruit

Good Day, It seem this url does not display decently inside internet explorer6 .

air conditioning Netherlands, on 12/4/2009 9:25:34 AM Said:

air conditioning

Hi There, It seem your blog doesnt display justly inside ie8.

Edible Fruit Netherlands, on 12/4/2009 10:20:52 AM Said:

Edible Fruit

Hi, It seem site doesnt show fitly in ie6.

air conditioning Netherlands, on 12/4/2009 10:47:25 AM Said:

air conditioning

Hello, It im sure website doesnt viewed justly inside google chrome.

Garry Jameson Netherlands, on 12/4/2009 12:21:33 PM Said:

Garry Jameson

Good Friend, It im sure this website doesnt display justly in ie7.

Garry Netherlands, on 12/4/2009 12:30:19 PM Said:

Garry

Hello, It seem this blog does not viewed nicely with ie7.

D.Trotter Netherlands, on 12/4/2009 12:42:48 PM Said:

D.Trotter

Hi There, It seem your blog doesnt display justly inside ie8.

Debra Trotter Netherlands, on 12/4/2009 12:50:16 PM Said:

Debra Trotter

Good Day, It seem your site does not show befittingly in firefox.

D.Trotter Netherlands, on 12/4/2009 1:08:03 PM Said:

D.Trotter

Hi There, It seem your blog doesnt display justly inside ie8.

Debra Netherlands, on 12/4/2009 1:08:07 PM Said:

Debra

Hi There, It seem this page does not display accurately in ie7.

Garry Netherlands, on 12/4/2009 1:27:24 PM Said:

Garry

Hello, It seem this blog does not viewed nicely with ie7.

Registry Easy United States, on 12/4/2009 1:28:28 PM Said:

Registry Easy

Looks like an interesting blog. Will make visit again.

Debra Trotter Netherlands, on 12/4/2009 1:35:26 PM Said:

Debra Trotter

Hi There, It seem blog doesnt display nicely in ie6.

D.Trotter Netherlands, on 12/4/2009 1:48:12 PM Said:

D.Trotter

Good Day, It looks like this site does not display decorously with ie7.

Garry Jameson Netherlands, on 12/4/2009 1:48:16 PM Said:

Garry Jameson

Good Day, It seem this url does not display decently inside internet explorer6 .

Garry Jameson Netherlands, on 12/4/2009 2:55:16 PM Said:

Garry Jameson

Hi, It im sure your page does not viewed decently in ie6.

Trotter Netherlands, on 12/4/2009 3:05:20 PM Said:

Trotter

Hello, It looks like url doesnt viewed fitly with firefox.

Speed up windows xp United States, on 12/5/2009 8:59:05 AM Said:

Speed up windows xp

Loved reading this post.

pandora jewelry People's Republic of China, on 12/14/2009 2:47:00 AM Said:

pandora jewelry

What should to modify in script.

Thanks sir.

cocktail dresses United States, on 12/14/2009 6:07:43 PM Said:

cocktail dresses

I having some problems here? in your blog you stated that we need to enable write permissions on the App_Data folder...unfortunately I don't understand how to enable it.

flash messenger United States, on 12/24/2009 12:27:10 AM Said:

flash messenger

So far, I managed to go though only some of posts you discuss here, but I find them very interesting and informative. Just want say thank you for the information you have shared. Regards

dallas auto accident attorney United Kingdom, on 12/24/2009 5:53:42 AM Said:

dallas auto accident attorney

I was very pleased to find this site.I wanted to thank you for this great read!! I definitely enjoying every little bit of it and I have you bookmarked to check out new stuff you post.

Miami Condos United Kingdom, on 12/24/2009 5:55:16 AM Said:

Miami Condos

Never knew that. Thanks for the info. I think your blog is going to do well. People will always return to read this kind of content. Great job.

Love Poems United States, on 12/25/2009 3:20:24 AM Said:

Love Poems

Thanks.. Funny, I actually had this on my mind a few days ago..

Web design company United States, on 12/30/2009 9:25:00 PM Said:

Web design company

Thanks for great stuff!

Emergency Dentist Melbourne United States, on 1/2/2010 8:48:08 PM Said:

Emergency Dentist Melbourne

With your help provided in this blog now i am able to make calendar extender control to show month / year.Thanks a lot for your help.

drug treatment center United Kingdom, on 1/4/2010 1:08:12 AM Said:

drug treatment center

Took me time to read all the comments, but I really enjoyed the article. It proved to be Very helpful to me and I am sure to all the commenters here! It's always nice when you can not only be informed, but also entertained!

guicci People's Republic of China, on 1/10/2010 2:53:48 AM Said:

guicci


We are a group of volunteers and starting a new initiative in a community|.

Your blog provided us valuable information to work on.You have done a marvellous job!

panic attacks United States, on 1/11/2010 3:56:44 AM Said:

panic attacks

nice post

airport bus New York United States, on 1/11/2010 4:37:57 AM Said:

airport bus New York


  You may have not intended to do so, but I think you have managed to express the state of mind that a lot of people are in. The sense of wanting to help, but not knowing how or where, is something a lot of us are going through.

new vans for sale United Kingdom, on 1/11/2010 11:19:44 AM Said:

new vans for sale

was there a solution found for successfully enabling 2 calendars?

Caviar United States, on 1/12/2010 2:31:27 AM Said:

Caviar

I recently came accross your blog and have been reading along. I thought I would leave my first comment. I dont know what to say except that I have enjoyed reading. Nice blog. I will keep visiting this blog very often.

ppo insurance plans United States, on 1/18/2010 1:28:08 AM Said:

ppo insurance plans

Wow! i agree! i’ve been searching for so long for a site where i could find everything that i want, and i’ve just found it!! really, i’ve visited your blog, and it’s amazing, i will keep visiting

Add comment


(Will show your Gravatar icon)

  Country flag

biuquote
  • Comment
  • Preview
Loading