I’ve a case where I have an ASP.NET calendar that has a page load method that automatically select a date when it’s loaded. I also have an event defined for Selected_Changed which will be triggered only when the user select any other date other than pre-selected date on the load
Private Sub ctlCalendar_SelectionChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles ctlCalendar.SelectionChanged If (Not String.IsNullOrEmpty(CalendarPreviousPage)) Then BaseCalendar.SelectedDate = ctlCalendar.SelectedDate Response.Redirect(CalendarPreviousPage) End If End Sub
But how do I wire up an event or when the selecteddate being clicked?You can use DayRender event and attach it to a javascript in this case I want to go back to previous page. BaseCalendar.Selected date can be any date where you want to set up/wire up the logic
Private Sub ctlCalendar_DayRender(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.DayRenderEventArgs) Handles ctlCalendar.DayRender Dim d As CalendarDay Dim c As TableCell d = e.Day c = e.Cell If (BaseCalendar.SelectedDate.Value = d.Date) Then c.Attributes.Add("OnClick", "history.go(-1)") End If End Sub
Leave a Reply