I am developing a ASP.NET web site, in which I have used a AJAX control Tool kit's CalendarExtender to select a date in asp:TextBox. I want to set the VisibleDate property of the asp:Calendar control based on the selected date from the CalendarExtender control. I request you to help me to achieve this functionality. Or Is there any way to post back the page on selection of date from CalendarExtender control so that I can handle TextChanged event 开发者_StackOverflowin the codebehind and set the VisibleDate property at within this event handler? Thanks
I would use an asynchronous postback on TextChanged-event to set the VisibleDate property:
aspx:
<asp:UpdatePanel ID="UdpDatePanel" runat="server" UpdateMode="conditional" ChildrenAsTriggers="false" >
<ContentTemplate>
<asp:Calendar ID="Calendar1" runat="server" />
<asp:TextBox ID="TxtDate" AutoPostBack="true" runat="server" />
<asp:CalendarExtender ID="CalendarExtender1" TargetControlID="TxtDate" runat="server" />
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="TxtDate" EventName="TextChanged" />
</Triggers>
</asp:UpdatePanel>
codebehind:
Public Partial Class CalendarDemo
Inherits System.Web.UI.Page
Private Sub TxtDate_TextChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles TxtDate.TextChanged
Dim d As Date
If Date.TryParse(Me.TxtDate.Text, d) Then
Me.Calendar1.VisibleDate = d
End If
End Sub
End Class
On this way it keeps performant and you don't have to mess around with javascript that might change in future releases of asp.net-ajax toolkit.
精彩评论