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

Thread is closed for posting
4 posts, 0 answers
  1. Telerik Admin
    Telerik Admin avatar
    1679 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. Raymond Dalton
    Raymond Dalton 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. Giuseppe
    Admin
    Giuseppe avatar
    2363 posts

    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. Maria Ilieva
    Admin
    Maria Ilieva avatar
    4017 posts

    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