![]() |
Web Development »
ASP.NET »
General
Intermediate
Date picker and Time picker in asp.net 2.0 using Ajax (With Atlas)By rperetzAdd a date picker and a time picker to your web pages |
Windows, .NET, ASP.NET, Visual Studio, Dev
|
||||||||
|
Advanced Search |
|
|
|
||||||||||||||||
In this article I will show you how to have a date picker and a time picker with almost no code, using Ajax (with Atlas). Having a good date picker can make the end user experience much better and after all your date is a valid date.
Here is a screen shoot of the final product:
| To pick a date: | ![]() |
| To pick a time: | ![]() |
| Results: | ![]() |
Please visit my first article to learn about Atlas and how to set up an Atlas Web Project: http://www.thecodeproject.com/useritems/Autocomplete.asp. (Read Step 1 and Step 2)
<%@ Register Assembly="AtlasControlToolkit" Namespace="AtlasControlToolkit" TagPrefix="cc1" %>
Let's Review the main properties of this control:
<asp:Panel ID="Panel1" runat="server" CssClass="popupControl"> <atlas:UpdatePanel ID="UpdatePanel1" runat="server"> <ContentTemplate> <atlasToolkit:PopupControlExtender ID="PopupControlExtender1" runat="server"><atlasToolkit:PopupControlProperties TargetControlID="txtUpdateDateFrom" PopupControlID="Panel1" Position="Bottom" /> </atlasToolkit:PopupControlExtender> Place your Calendar asp.net control </ContentTemplate> </atlas:UpdatePanel> </asp:Panel>
The code is very easy to follow, if you want to learn more about the UpdatePanel control go to : http://atlas.asp.net/docs/Server/Microsoft.Web.UI/UpdatePanel/default.aspx (download sample project to have complete code)
protected void Calendar1_SelectionChanged(object sender, EventArgs e)
{
// Popup result is the selected date
PopupControlExtender1.Commit(txtUpdateDateFrom, Calendar1.SelectedDate.ToShortDateString());
}
<asp:TextBox ID="txtTimeFrom" runat="server" Width="50"></asp:TextBox>
<asp:Panel ID="PanelTime" runat="server" CssClass="popupControl" >
<div style="border:1px outset white" >
<atlas:UpdatePanel ID="UpdatePanel4" runat="server">
<ContentTemplate>
<atlasToolkit:PopupControlExtender ID="PopupControlExtender3" runat="server">
<atlasToolkit:PopupControlProperties TargetControlID="txtTimeFrom"
PopupControlID="PanelTime" CommitProperty="value" Position="Bottom" />
</atlasToolkit:PopupControlExtender>
<asp:RadioButtonList ID="RadioButtonTimeFrom" runat="server" OnSelectedIndexChanged="RadioButtonTimeFrom_SelectedIndexChanged" AutoPostBack="true" RepeatColumns="4" RepeatDirection ="Horizontal" >
<asp:ListItem Text="0:00"></asp:ListItem>
<asp:ListItem Text="0:30"></asp:ListItem>
<asp:ListItem Text="1:00"></asp:ListItem>
<asp:ListItem Text="1:30"></asp:ListItem>
<asp:ListItem Text="2:00"></asp:ListItem>
<asp:ListItem Text="2:30"></asp:ListItem>
<asp:ListItem Text="3:00"></asp:ListItem>
<asp:ListItem Text="3:30"></asp:ListItem>
<asp:ListItem Text="4:00"></asp:ListItem>
<asp:ListItem Text="4:30"></asp:ListItem>
<asp:ListItem Text="5:00"></asp:ListItem>
<asp:ListItem Text="5:30"></asp:ListItem>
<asp:ListItem Text="6:00"></asp:ListItem>
<asp:ListItem Text="6:30"></asp:ListItem>
<asp:ListItem Text="7:00"></asp:ListItem>
<asp:ListItem Text="7:30"></asp:ListItem>
<asp:ListItem Text="8:00"></asp:ListItem>
<asp:ListItem Text="8:30"></asp:ListItem>
<asp:ListItem Text="9:00"></asp:ListItem>
<asp:ListItem Text="9:30"></asp:ListItem>
<asp:ListItem Text="10:00"></asp:ListItem>
<asp:ListItem Text="10:30"></asp:ListItem>
<asp:ListItem Text="11:00"></asp:ListItem>
<asp:ListItem Text="11:30"></asp:ListItem>
<asp:ListItem Text="12:00"></asp:ListItem>
<asp:ListItem Text="12:30"></asp:ListItem>
<asp:ListItem Text="13:00"></asp:ListItem>
<asp:ListItem Text="13:30"></asp:ListItem>
<asp:ListItem Text="14:00"></asp:ListItem>
<asp:ListItem Text="14:30"></asp:ListItem>
<asp:ListItem Text="15:00"></asp:ListItem>
<asp:ListItem Text="15:30"></asp:ListItem>
<asp:ListItem Text="16:00"></asp:ListItem>
<asp:ListItem Text="16:30"></asp:ListItem>
<asp:ListItem Text="17:00"></asp:ListItem>
<asp:ListItem Text="17:30"></asp:ListItem>
<asp:ListItem Text="18:00"></asp:ListItem>
<asp:ListItem Text="18:30"></asp:ListItem>
<asp:ListItem Text="19:00"></asp:ListItem>
<asp:ListItem Text="19:30"></asp:ListItem>
<asp:ListItem Text="20:00"></asp:ListItem>
<asp:ListItem Text="20:30"></asp:ListItem>
<asp:ListItem Text="21:00"></asp:ListItem>
<asp:ListItem Text="21:30"></asp:ListItem>
<asp:ListItem Text="22:00"></asp:ListItem>
<asp:ListItem Text="22:30"></asp:ListItem>
<asp:ListItem Text="23:00"></asp:ListItem>
<asp:ListItem Text="23:30"></asp:ListItem>
<asp:ListItem Text="23:59"></asp:ListItem>
</asp:RadioButtonList>
</ContentTemplate>
</atlas:UpdatePanel>
</div>
</asp:Panel>
<div style="border:1px outset white" >
Let's See the code for OnSelectedIndexChanged Event for the RadioButtonList
protected void RadioButtonTimeFrom_SelectedIndexChanged(object sender, EventArgs e) { if (!string.IsNullOrEmpty(RadioButtonTimeFrom.SelectedValue)) { // Popup result is the selected task PopupControlExtender3.Commit(txtTimeFrom, RadioButtonTimeFrom.SelectedValue); } else { // Cancel the popup PopupControlExtender3.Cancel(txtTimeFrom); } // Reset the selected item RadioButtonTimeFrom.ClearSelection(); }
<atlas:UpdateProgress id="process1" runat ="server">
<ProgressTemplate>
<div class = "title">
<img src="images/updating_anim.gif" />Please wait, the page is loading...
</div>
</ProgressTemplate>
</atlas:UpdateProgress>
1. download the zip file
2. copy all the folder "TimePicker" to your web site folder (C:\Documents and Settings\[your name]\My Documents\Visual Studio 2005\WebSites)
3. Open VS2005 and Create a new C# web site called "TimePicker" (don't need to select the Atlas template since my site already have all the Atlas dlls) and point the site to the location you saved your folder (C:\Documents and Settings\[your name]\My Documents\Visual Studio 2005\WebSites\AtlasTextBoxAutoComplete)
4. VS2005 will give you a message saying "Web Site already exists", now you select "Open the existing web site" and push ok
5. click on default.aspx (to make it your start up page) and run.
6. Run Default.aspx
Feel free to leave any feedback on this article or any questions you may have.
Ronnie Peretz
PHP (People Helping People)
General
News
Question
Answer
Joke
Rant
Admin
|
PermaLink |
Privacy |
Terms of Use
Last Updated: 2 Aug 2006 Editor: |
Copyright 2006 by rperetz Everything else Copyright © CodeProject, 1999-2009 Web18 | Advertise on the Code Project |