Categories

Tools

bitdefender

1&1 Web Hosting

An example of using ASP.NET Calendar control inside an UpdatePanel


The following example shows how to use the control ASP.NET Calendar control to select a date. The Calendar was inserted inside an UpdatePanel in order to make updates without having to reload the entire page.

Code:

<asp:ScriptManager ID="ScriptManagerCalendar" runat="server">
</asp:ScriptManager>
<asp:UpdatePanel ID="UpdatePanelCalendar" runat="server">
	<ContentTemplate>
		<asp:Label ID="LabelDate" runat="server" Text="Date:"></asp:Label>
		<asp:TextBox ID="TextBoxDate" runat="server" Font-Size="Small"
			Height="10"
			ReadOnly="true"
			Width="80px" ></asp:TextBox> 
		<asp:ImageButton ID="ImageButtonCalendar" runat="server" 
			ImageUrl="~/images/calendar.gif" 
			OnClick="ImageButtonCalendar_Click" />

		<asp:Calendar ID="Calendar" runat="server" 
			BackColor="#FFFFCC" 
			BorderColor="#FFCC66" 
			BorderWidth="1px" 
			DayNameFormat="Shortest" 
			Font-Names="Verdana" 
			Font-Size="8pt" 
			ForeColor="#663399" 
			Height="200px" 
			ShowGridLines="True"
			Visible="false"
			Width="220px" 
			OnSelectionChanged="Calendar_SelectionChanged">
			<DayHeaderStyle BackColor="#FFCC66" Font-Bold="True" Height="1px" />
			<NextPrevStyle Font-Size="9pt" ForeColor="#FFFFCC" />
			<OtherMonthDayStyle ForeColor="#CC9966" />
			<SelectedDayStyle BackColor="#CCCCFF" Font-Bold="True" />
			<SelectorStyle BackColor="#FFCC66" />
			<TitleStyle BackColor="#990000" Font-Bold="True" Font-Size="9pt" ForeColor="#FFFFCC" />
			<TodayDayStyle BackColor="#FFCC66" ForeColor="White" />
		</asp:Calendar>
	</ContentTemplate>
</asp:UpdatePanel>

In the code-behind

Code:

/// <summary>
/// View the Calendar control
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void ImageButtonCalendar_Click(object sender, ImageClickEventArgs e)
{
	Calendar.Visible = true;
}

/// <summary>
/// Gets the selected date on the Calendar control and writes in TextBox
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void Calendar_SelectionChanged(object sender, EventArgs e)
{
	DateTime dt = Calendar.SelectedDate;
	TextBoxDate.Text = dt.ToString("dd/MM/yyyy");
	Calendar.Visible = false;
}

Here is the result of the example:

An example of using ASP.NET Calendar control inside an UpdatePanel

Posted in ASP.NET by MdmSoft

If our work has been of help, you can help us with a small donation...
Our programmers will thank you!



All information contained in this web site are the property of MdmSoft. The information is provided "as is", MdmSoft will not be liable for any misuse of the code contained in these pages, nor can it be for inaccuracies, grammatical errors or other factors that may have caused damage or lost earnings. MdmSoft is not responsible for the content of comments posted by users.
The examples in this area have the educational and demonstration purposes only, and may be copied only for your reference, but cannot be used for commercial purposes, or for any other purpose, without the express written consent of MdmSoft.
MdmSoft also reserves the right to change, without notice, to your liking this web site, the pages and its sections, and may suspend temporarily or definitely the various services included on this site.
While using this site, you agree to have read and accepted our Terms of Service and Privacy Policy.