Calendar Popup Custom Control

I have to maintain existing ASP.NET application that used eWorld.UI.CalendarPopup custom control to show calendar in a small popup window.

The users complained that the popup window not always rendered correctly if shown in front of other controls and if the control is on the bottom of visible part of the browser window, most of popup calendar is cut off.

I've tried to download the latest version of the eWorld.UI.CalendarPopup  and found that it is currently not available.

I've tried a few free controls from http://www.411asp.net/home/assembly/datetime and from http://weblogs.asp.net/datagridgirl/archive/2004/02/05/68105.aspx

but most of them do not position well when the contol is located near the bootom of the page.

Finally I found Matt Kruse JavaScript Calendar Popup control (PLEASE SUPPORT HIS SITE) that works as it is required.

I've created an ASP.Net custom control as a wrupper to Matt's JavaScript to make it easier to include in ASP.NET pages.

My custom control has only a few properties that I needed and doesn't expose all options that Matt's JavaScript allowed.

If required it can be extended.

      ///

      /// DatePicker -one more attempt to do the same things

      /// it's ASP.NET wrapper for Matt Kruse Calendar Popup http://www.mattkruse.com/javascript/calendarpopup/index.html

      /// I had to replace eWorld.UI.CalendarPopup

      ///

      // TODO : if the control is in the frame, it can position far below the parent control (see DSP\AddSchoolInfo)

      [DefaultProperty("Text"),

            ToolboxData("<{0}:DatePicker runat=server>")]

      public class DatePicker :  Control, INamingContainer 

      { //,IPostBackDataHandler

            //private string m_text;use ViewState instead

            public DatePicker() : base()

            {

            }

            #region   "Private properties"

            private TextBox m_txtDate;

            private HyperLink  m_lnkSelect;

            #endregion  // "Private properties"

 

#region   "Public properties"

           

            [Bindable(true),

                  Category("Appearance"),

                  DefaultValue(""),

            EditorAttribute(typeof(System.Web.UI.Design.ImageUrlEditor), typeof(UITypeEditor))]

            public   string ImageUrl 

            {

                  get

                  {

                        this.EnsureChildControls();

                        return m_lnkSelect.ImageUrl;

                  }

                  set

                  { 

                        this.EnsureChildControls();

                        m_lnkSelect.ImageUrl = value;

                  }

            }

 

            [Bindable(true),

            Category("Appearance"),

            DefaultValue("")

            ]

            public  string Text

            {

                  get

                  {

                        return TextBox.Text;

                  }

                  set

                  { 

                        TextBox.Text = value;

                  }

            }

///

/// Property TextBox (TextBox)

///

public TextBox TextBox

{

      get

      {

            this.EnsureChildControls();

            return this.m_txtDate;

      }

      set

      {

            this.EnsureChildControls();

            this.m_txtDate = value;

      }

}

            [Category("Data"), Bindable(true)]

            public DateTime SelectedDate

            {

                  get

                  {

                       

                        if (DataHelper.IsNullOrEmpty(TextBox.Text)==false)

                        {

                              return (DateTime) Convert.ToDateTime(TextBox.Text) ;

                        }

                        return new DateTime();

                  }

                  set

                  {

                        TextBox.Text = value.ToShortDateString() ;

                  }

            }

 

            private const  string  cnstJavaScriptUrlName  = "JavaScriptUrl";

            ///

            /// ViewState Property JavaScriptUrl

            ///

            public string JavaScriptUrl

            {

                  get

                  {

                        return  (string)ViewState[cnstJavaScriptUrlName];

                  }

                  set

                  {

                              ViewState[cnstJavaScriptUrlName] = value;

                  }

            }

            #endregion  // "Public properties"

 

            ///

            /// Overrides

            ///

            protected override void OnLoad(System.EventArgs e)

            {

                  base.OnLoad(e);

                  this.EnsureChildControls();

                  InitCalendarPopupControl(this.m_txtDate,this.m_lnkSelect );

            }

 

            protected override void CreateChildControls()

            {

 

                  m_txtDate = new TextBox();

                  m_txtDate.ID="txtDate";

                  this.Controls.Add(m_txtDate);

                  m_lnkSelect = new HyperLink();

                  m_lnkSelect.ID="lnkSelect";

                  this.Controls.Add(m_lnkSelect);

            }

            protected void InitCalendarPopupControl(TextBox txtDate,HyperLink  lnkSelect)

            { //from http://www.mattkruse.com/javascript/calendarpopup/index.html)

                  Page page=txtDate.Page;

                  string sClndrId="clndr"+txtDate.ID;

                  string sDecl="var " + sClndrId + " = new CalendarPopup();";

                  page.RegisterStartupScript( sClndrId,JScriptHelper.JScript(sDecl));

                  string srcPath=JavaScriptUrl;// "~/js/CalendarPopup.js";

                  if(DataHelper.IsNullOrEmpty(srcPath))

                  {

                    srcPath= ResSrvHandler.ResourceUrl("CalendarPopup.js",true );  

                  }

                  JScriptHelper.RegisterStartupScriptUrl(page,srcPath);

                  string sJScriptSrc=@" ";

                  page.RegisterClientScriptBlock( "CalendarPopup.js",sJScriptSrc);

                  //          "cal.select(document.forms['example'].date1,'anchor1','MM/dd/yyyy'); return false;"

                  string sInvokePopupCal=sClndrId+".select(document.forms[0]." + txtDate.ClientID + ",'" + lnkSelect.ClientID  + "','dd/MM/yyyy')";

                  page.RegisterStartupScript( sClndrId,sDecl);

                  //very similar to DNN C:\Visual Studio Projects\FuncSoln\FSDNN\components\Shared\Calendar.vb

                  lnkSelect.NavigateUrl="javascript:" + sInvokePopupCal;

            }

 

 

      }

 

  

  • Share This Post:
  • Share on Twitter
  • Share on Facebook
  • Share on Technorati
posted @ Monday, December 05, 2005 2:21 PM
Print

Comments on this entry:

# re: Calendar Popup Custom Control

Left by edward at 12/31/2005 2:15 AM
Gravatar
Is this ASP.NET 2.0 code? I am getting build errors like: "The type or namespace name 'Design' does not exist in the class or namespace 'System.Web.UI' (are you missing an assembly reference?)" I'm having a hard time as I am rather new to .NET stuff.

# re: Calendar Popup Custom Control

Left by Michael Freidgeim at 1/3/2006 6:03 AM
Gravatar
Edward,
The code was written for ASp.NET 1.1 but I've compiled it witt 2.0.
I didn't include in the post a few using statements, that are required at the beginning of the class:
using System;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.ComponentModel;
using System.Web.UI.Design; //!!!System.Design (in System.Design.dll)
using System.Drawing.Design;
using System.Collections.Specialized;//NameValueCollection Class
using System.Diagnostics;
using FSHelperLib;
using EWSoftware.Web;

# re: Calendar Popup Custom Control

Left by Cody Swoyer at 1/14/2008 10:36 PM
Gravatar
I just wanted to touch base with you to thank you for supporting 411asp.net and linking to us. In light of your support, I wanted to give you a heads up on some new things we've got in the works.

We're taking 411asp to the next level by a launching a second generation site under a new name: Codango.com. Codango has much of the same content as 411asp, but with some slick new features like screenshots, editorial reviews, demo links, a redesigned look, and more.

We want to ask you if you could update the links on your website to include Codango.com. Since you've been a supporter of 411asp all this time, we're really hoping for your help during this transition.

Would you be able to do this for us? I'll be looking forward to your reply!

Best wishes and warm regards,

Cody Swoyer

# re: Calendar Popup Custom Control

Left by Michael Freidgeim at 1/14/2008 10:38 PM
Gravatar
Hi Cody,
I would update these links, when I will have time for blog maintenance.

# re: Calendar Popup Custom Control

Left by patrick at 6/19/2008 5:13 PM
Gravatar
hi, please can you help me? everytime i set the date in calendar popup, i cannot get the value of the selected date.

Your comment:



(not displayed)


 
 
 
 
 

Live Comment Preview:

 
«February»
SunMonTueWedThuFriSat
2930311234
567891011
12131415161718
19202122232425
26272829123
45678910