Adding A Popup Calendar to Your DNN Module 

Recently when working on modules for clients and enhancements for my own modules I have been looking for better ways to utilize core DotNetNuke functionaltiy.  This article is the first in a long series of articles that I will be posting regarding using DotNetNuke core functions and controls in custom modules.  This first article will walk you through the process to add a simple popup calendar as an option for a user that is being prompted for a date.  Many people do not know that DotNetNuke provides a very nifty interface that handles all the hard work.  This article will walk you through this step by step, first with the .ascx code, then the .cs or .vb code, the lastly with a screencapture of the component in action.

The User Control Code (.ascx)

Nothing special is needed to accomplish this effect, for this example we simply create a textbox called StartDate and an image called CalendarImage.  If you notice the source for the calendar image references a calendar icon that is provided by the DotNetNuke core.  You can put your own image in if you desire by including it in your module package.

<asp:TextBox ID="StartDate" runat="server" MaxLength="10" />
<
asp:Image ID="CalendarImage" runat="server" ImageUrl="~/Images/Calendar.png" />

This is it for the front end of the interface, next we will move on to the codebehind

The Code Behind (.cs or .vb)

The code needed to complete the process is very simple.  I broke the below examples into two parts to make it easier for you to read here in the blog, but you could actually accomplish the entire task on one line of code.  We call a DotNetNuke method to get an invoke URL to show the calendar, then we add an OnClick action for our image to call that url.  When the window is closed inside the calendar, the date value selected will be returned to the page and put in the proper textbox.

C#

string path DotNetNuke.Common.Utilities.Calendar.InvokePopupCal(StartDate);
CalendarImage.Attributes.Add("OnClick", path);

VB

Dim path As String = DotNetNuke.Common.Utilities.Calendar.InvokePopupCal(StartDate)
CalendarImage.Attributes.Add(
"OnClick", path)

This code should be added to your modules Page_Load event and only needs to be executed for the first load of a page.  This completes the process.

Action Shot

Below is a screen capture of the above demo in action!

In Action

Conclusion

I hope this quick overview of adding a popup calendar to your DotNetNuke module has been helpful. Please share your comments below, also I am taking requests for the next DotNetNuke function/control to go over in a similar fashion.

Posted by Mitchel on Monday, May 12, 2008
 

Comments

Mitch - the DNN default calendar popup seems to have issues in Firefox. It's cut off on the right and never seems to fully load.

By Tom Kraak on Thursday, May 15, 2008 at 5:18 PM

Mitch - the DNN default calendar popup seems to have issues in Firefox. It's cut off on the right and never seems to fully load.

By Tom Kraak on Thursday, May 15, 2008 at 5:18 PM

Tom,

You are right....that isn't good!

I wonder what causes it....I'll try to look into it, it is a core bug for sure, it affects all areas where the popup cal is used..

By mitchel.sellers@gmail.com on Thursday, May 15, 2008 at 6:15 PM

Another great tip! Over the years I have always used the word "Calendar" whereas the image looks much better - making a note to update my modules!

PS - yes, my calendar on PokerDIY.com gets cut off too. I have just upgraded to 4.8, don't think it was an issue in 4.6.2.

Thanks
Rodney Joyce
Smart-Thinker.com

By Rodney Joyce on Wednesday, May 21, 2008 at 7:25 PM

The DNN calendar has two main problems for us. (1) It is too small. We needed to go into the .css file and make it larger. Now we can see it. (2) We could only find one way to link to another module and that was by including a link in the comments section. That means we first select the event on the calendar which brings up a description. In the description is a comments section where a link is shown. Would prefer to have the option of going directly to the link from the calendar event.

By Bob Garmise on Friday, May 30, 2008 at 7:42 AM

Comments from the following blog entry: Smart-Thinker UserProfile 4.3.11 Released , located at: http://www.smart-thinker.com/Default.aspx?tabid=1070&EntryID=37

By Smart-Thinker DotNetNuke Development Blog on Saturday, June 07, 2008 at 5:15 PM

Comments from the following blog entry: Smart-Thinker UserProfile 4.3.11 Released , located at: http://www.smart-thinker.com/Default.aspx?tabid=1070&EntryID=37

By Smart-Thinker DotNetNuke Development Blog on Saturday, June 07, 2008 at 5:40 PM

Could You give me source codes? I too wish to add a calendar in the module but it does not turn out in any way :(

By Pavel on Tuesday, July 29, 2008 at 9:58 PM

Hi,
I wounder when i trying to use calender pop i got few thing.

Popup calender window appearing and after selecting date it is showing.

Problem is when i click Update. It Automatically clear the Textfield which bind that date.
I tried both way put it in page load event with out postback or with postback but nothing work. imgdate.attribute.add("onclick",attrib)

Let me know where i m making mistake

By Ajit on Sunday, November 02, 2008 at 5:35 AM
Click here to post a comment

Donate

Show your appreciation for the content/modules made available by MitchelSellers.com by making a donation. Donations are used to assist with dedicating time to creating free content.