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

Thread is closed for posting
4 posts, 0 answers
  1. 63F75A2C-1F16-4AED-AFE8-B1BBD57646AD
    63F75A2C-1F16-4AED-AFE8-B1BBD57646AD avatar
    1572 posts
    Member since:
    Oct 2004

    Posted 03 Apr 2006 Link to this post

     

    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.
  2. 568CD6A9-87C1-4DD1-A149-9E2B23C5E032
    568CD6A9-87C1-4DD1-A149-9E2B23C5E032 avatar
    4 posts
    Member since:
    Sep 2002

    Posted 23 Aug 2006 Link to this post

    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

  3. FCA2D288-F6EC-4724-BAB8-B03BBE745D7B
    FCA2D288-F6EC-4724-BAB8-B03BBE745D7B avatar
    2363 posts
    Member since:
    Mar 2023

    Posted 23 Aug 2006 Link to this post

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


    Best wishes,
    Manuel

    the telerik team
  4. 272EA702-B83F-49DA-9608-0FBC5A6ECAEB
    272EA702-B83F-49DA-9608-0FBC5A6ECAEB avatar
    4017 posts
    Member since:
    Oct 2016

    Posted 14 Aug 2008 Link to this post


    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

This Code Library is part of the product documentation and subject to the respective product license agreement.