Get the same selected date from the calendar two consecutive times

G

Guest

When I click any date in System.Web.UI.WebControls.Calendar (C# WebForm), the SelectionChanged event handler fires. If I next click on the same date again, this event handler does not fire, so I can't get the selected date directly from the calendar on two successive attempts

How can I get this same selected date from the calendar on two successive attempts. Storing the value obtained on the first attempt isn't helpful.
 
K

Ken Cox [Microsoft MVP]

This might be a hack but it seems to work... call SelectionChanged
yourself....

Private Sub Page_Load _
(ByVal sender As System.Object, _
ByVal e As System.EventArgs) _
Handles MyBase.Load
If IsPostBack Then
If viewstate("stopcalendarchange") _
<> True Then
Call Calendar1_SelectionChanged _
(Calendar1, Nothing)
End If
End If
End Sub

Private Sub Calendar1_SelectionChanged _
(ByVal sender As Object, _
ByVal e As System.EventArgs) _
Handles Calendar1.SelectionChanged
Label1.Text = _
Calendar1.SelectedDate.ToLongDateString & _
" at " & Now.ToLongTimeString
End Sub

Private Sub Button1_Click _
(ByVal sender As System.Object, _
ByVal e As System.EventArgs) _
Handles Button1.Click
viewstate("stopcalendarchange") = True
Label1.Text = "Stopped getting same date."
' Calendar1.Enabled = False
' Calendar1.Visible = False
End Sub

<form id="Form1" method="post" runat="server">
<asp:Calendar id="Calendar1" runat="server"></asp:Calendar>
<P>
<asp:Label id="Label1" runat="server"></asp:Label></P>
<P>
<asp:Button id="Button1" runat="server" Text="Stop getting same
date"></asp:Button></P>
</form>

Ken
Microsoft MVP [ASP.NET]
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,766
Messages
2,569,569
Members
45,045
Latest member
DRCM

Latest Threads

Top