|
|||||||||||||||||||||||||||||
|
|||||||||||||||||||||||||||||
|
Announcements
Chapters
Services
Feature Zones
|
Note: This is an unedited contribution. If this article is inappropriate,
needs attention or copies someone else's work without reference then please
Report This Article
IntroductionIn 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.
Setup up your Atals/AJAX Web ProjectPlease 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) Say Hi to Atlas PopupControlExtender ControlHere is the easiest way to get PopupControlExtender Atlas Control in your Page:<%@ Register Assembly="AtlasControlToolkit" Namespace="AtlasControlToolkit" TagPrefix="cc1" %>
Let's Review the main properties of this control: Hook up the calendar control with PopupControlExtenderWe are going to use a Panel control to be our pop up, and have a asp.net calendar control inside the panel. with the help of PopupControlExtender and UpdatePanel Control we can hook all this up. Let's have a look at the code:<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) Ho Yes there is a bit of code tooLet's have a look at the code to handle calendar changes
protected void Calendar1_SelectionChanged(object sender, EventArgs e)
{
// Popup result is the selected date
PopupControlExtender1.Commit(txtUpdateDateFrom, Calendar1.SelectedDate.ToShortDateString());
}
Here you can change the formatting of the selected date in this example I use Calendar1.SelectedDate.ToShortDateString(). and that's all, you got yourself a date picker Let's have a time picker tooUsing the same idea we did our date picker we can do a time picker as well, only now I will put a RadioButtonList control instead of a colander control. again our panel will do the job of the pop up, only this time we need to a div style to make it look like a pop up, let's have a look at the full code:
Ok very similar to the date picker, here are some points to keep in mind:
and we close the div just before the Panel tag ends 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(); } How can I tell my users that my page is busy doing a postback with Atlas?Ajax is doing async postbacks, (you have to wait for the page to finsh loading), there may be some latency for longer running processes and you want to provide users some feedback/progress indicators. Using the UpdateProgress enables you to implement a progress template to display when controls are "InPostback." you can put this code just after the atlas:ScriptManage control:
Every time the page does a postback, you will see the image and the message: "Please wait, the page is loading...". Note: I am looking for a way to disable the input controls while the page is posting back, so the user can't change his input while the page is posting. I will update this article once I find a good way. Here are the steps to run my code1. download the zip file FeedbackFeel free to leave any feedback on this article or any questions you may have.
|
||||||||||||||||||||||||||||