Geeks With Blogs

News My Blog has been MOVED to https://mfreidge.wordpress.com
Michael Freidgeim's OLD Blog My Blog has been MOVED to https://mfreidge.wordpress.com

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;

            }

 

 

      }

 

  

Posted on Monday, December 5, 2005 2:21 PM | Back to top


Comments on this post: Calendar Popup Custom Control

# re: Calendar Popup Custom Control
Requesting 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.
Left by edward on Dec 31, 2005 2:15 AM

# re: Calendar Popup Custom Control
Requesting 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;
Left by Michael Freidgeim on Jan 03, 2006 6:03 AM

# re: Calendar Popup Custom Control
Requesting 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
Left by Cody Swoyer on Jan 14, 2008 10:36 PM

# re: Calendar Popup Custom Control
Requesting Gravatar...
Hi Cody,
I would update these links, when I will have time for blog maintenance.
Left by Michael Freidgeim on Jan 14, 2008 10:38 PM

# re: Calendar Popup Custom Control
Requesting Gravatar...
hi, please can you help me? everytime i set the date in calendar popup, i cannot get the value of the selected date.
Left by patrick on Jun 19, 2008 5:13 PM

Your comment:
 (will show your gravatar)


Copyright © Michael Freidgeim | Powered by: GeeksWithBlogs.net