Skip Navigation LinksHome / Community & Support / Code Library / ASP.NET and ASP.NET AJAX > Calendar > Replacing blank datepicker date with today's date (Net2.0, VB.NET)

Replacing blank datepicker date with today's date (Net2.0, VB.NET)

Feed from this thread
  • Posted on Apr 3, 2006 (permalink)

     

    Requirements

    RadCalendar for ASP .NET version

    RadControls for ASP .NET AJAX version

    1.5.1 and later



    2008.1.415 and later

    .NET version

    2.0 (RadCalendar for ASP .NET)


    2.0 and later (RadControls for ASP .NET AJAX)

    Visual Studio version

    2005/2008 (RadCalendar for ASP .NET)


    2005 and later(RadControls for ASP .NET AJAX)

    Programming language

    VB.NET

    Browser support

    all supported by RadCalendar for ASP .NET


    all browsers supported by RadControls for ASP .NET AJAX


     
    This sample application demonstrates customization of the datepicker control through the ChildrenCreated server-side event.

    The idea is to replace the initial blank date of the datepicker with today's date on calendar popup opening or on the input field receiving focus.

    This application is provided by Michael Weinberger.

  • Raymond Dalton avatar

    Posted on Aug 23, 2006 (permalink)

    Thanks for the code.  This is very useful.  I added the capability to set the date to today's date (easily editable) when the control loads.  I did this server side, as client side does not have an onload event.

    dpStartDate and dpEndDate are date picker controls for providing a date range.  The image directory was changed from your example to fit my example directory structure.

    Protected Sub dpStartDate_ChildrenCreated(ByVal sender As Object, ByVal e As System.EventArgs) Handles dpStartDate.ChildrenCreated

    SetDatePickerToCurrentDate(sender, e)

    End Sub

    Protected Sub dpEndDate_ChildrenCreated(ByVal sender As Object, ByVal e As System.EventArgs) Handles dpEndDate.ChildrenCreated

    SetDatePickerToCurrentDate(sender, e)

    End Sub

    Protected Sub SetDatePickerToCurrentDate(ByVal sender As Object, ByVal e As System.EventArgs)

    Dim picker As Telerik.WebControls.RadDatePicker = CType(sender, Telerik.WebControls.RadDatePicker)

    picker.SelectedDate = Today.Date

    'there is no way to accomplish the following that I have found
    ' picker.DateInput.Attributes("onload") = String.Format("var date = window.{0}.GetDate();date.setDate(date.getDate() + 1);window.{0}.SetDate(date);", picker.ClientID, picker.DateInput.ClientID, picker.MinDate.Year, picker.MinDate.Month - 1, picker.MinDate.Day)

    picker.PopupButton.Attributes("onclick") = String.Format("if (window.{0}.GetDate().toString() == new Date({2}, {3}, {4}).toString()){{window.{0}.SetDate(new Date());}} return window['{0}'].TogglePopup();", picker.ClientID, picker.DateInput.ClientID, picker.MinDate.Year, picker.MinDate.Month - 1, picker.MinDate.Day)

    picker.PopupButton.Attributes("onkeypress") = String.Format("if (window.{0}.GetDate().toString() == new Date({2}, {3}, {4}).toString()){{window.{0}.SetDate(new Date());}} return window['{0}'].TogglePopup();", picker.ClientID, picker.DateInput.ClientID, picker.MinDate.Year, picker.MinDate.Month - 1, picker.MinDate.Day)

    picker.DateInput.Attributes("onfocus") = String.Format("if (window.{0}.GetDate().toString() == new Date({2}, {3}, {4}).toString()){{window.{0}.SetDate(new Date()); this.select();}} return false;", picker.ClientID, picker.DateInput.ClientID, picker.MinDate.Year, picker.MinDate.Month - 1, picker.MinDate.Day)

    Dim clearButton As New ImageButton()

    clearButton.Attributes("onclick") = String.Format("window.{0}.DateInput.Clear(); return false;", picker.ClientID)

    clearButton.ImageUrl = "~/Images/Delete.gif"

    picker.Controls.Add(clearButton)

    End Sub

    Thanks again for the code sample,

    Raymond

  • Giuseppe Giuseppe admin's avatar

    Posted on Aug 23, 2006 (permalink)

    Thank you for sharing your approach and enhancement, Raymond, your points have been updated.


    Best wishes,
    Manuel

    the telerik team

  • Maria Ilieva Maria Ilieva admin's avatar

    Posted on Aug 14, 2008 (permalink)


    Find attached the Telerik.Web.UI version of the sample.
    The main changes are due to the new RadCalendar Cliend-Side API.

Back to Top

Skip Navigation LinksHome / Community & Support / Code Library / ASP.NET and ASP.NET AJAX > Calendar > Replacing blank datepicker date with today's date (Net2.0, VB.NET)