Hello,
I have a problem with events not firing. I've created a web user
control which renders a calendar using a table control. In two cells
I'm adding LinkButtons for "prev/next month". However, the events from
these are not fired.
In the PageLoad event I check if it's a PostBack. If it isn't, I'm
calling DisplayCalendar() to render the calendar. This part works and I
get the output. If it *is* a postback (i.e. one of the linkbuttons are
clicked), the PageLoad skipps to call DisplayCalendar(), but then the
event handler for either LinkButton is supposed to be fired next
(right?) - in which the current month is updated and then the
DisplayCalendar() would be called. This is not happening, what am I
missing?? Code snippet below:
Public Class calendar
Inherits System.Web.UI.UserControl
Protected WithEvents m_lnkPrevMonth As New
Web.UI.WebControls.LinkButton
Protected WithEvents m_lnkNextMonth As New
Web.UI.WebControls.LinkButton
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
If (Not IsPostBack) Then
DisplayCalendar()
End If
End Sub
Public Sub PrevMonth_Click(ByVal sender As Object, ByVal e As
System.EventArgs) Handles m_lnkPrevMonth.Click
CurrentDate = DateAdd(DateInterval.Month, -1, CurrentDate)
DisplayCalendar()
End Sub
Public Sub NextMonth_Click(ByVal sender As Object, ByVal e As
System.EventArgs) Handles m_lnkNextMonth.Click
CurrentDate = DateAdd(DateInterval.Month, 1, CurrentDate)
DisplayCalendar()
End Sub
Private Property CurrentDate() As Date
'Date stored in ViewState
....
End Property
Private Sub DisplayCalendar()
'Render the calendar
Dim objTable As New Web.UI.WebControls.Table
Dim objRow As Web.UI.WebControls.TableRow
Dim objCell As Web.UI.WebControls.TableCell
....
'Add link
m_lnkPrevMonth.Text = "«" ' «
objCell.Controls.Add(m_lnkPrevMonth)
objRow.Controls.Add(objCell)
....
'Add link
m_lnkNextMonth.Text = "»" ' »
objCell.Controls.Add(m_lnkNextMonth)
objRow.Controls.Add(objCell)
....
'Output the control
Me.Controls.Add(objTable)
End Sub
End Class