Time Picker Ajax Extender Control
Title: Time Picker Ajax Extender Control Author: Mohammed Farhan Ejaz Email: farhan_2b@rediffmail.com, farhan.ejaz@gmail.com Language: C# 2.0, 3.5, Javascript Platform: Web Technology: Asp.net Ajax Level: Advanced Description: A TimePicker Extender Control Section Ajax SubSection Controls License: CPOL
Introduction
The Time Picker is an Ajax Extender Control which can be used to input time.
It tries to fill the gap of such extender not available under the Ajax Control Toolkit.
Extender controls can be used to enhance the client functionality of ASP.NET Web server controls.
You do not use extender controls by themselves. Instead, you attach them to another ASP.NET Web server control.
Extender controls are attached to a Web server control by setting the TargetControlID property of the extender control
to the ID of the server control being extended.
The library download includes:
- Help File
- Binaries
- Source with Demo Application
Background
While working for a project, I came across a need to have users enter time the way they can choose a date from the Calendar Control. Being aware of the fact that Microsoft does not provides any such control out of the box I started looking out for other options. There were some good solutions available but most of them were using client scripting (Jquery/Javascript).
This is when I stumbled upon these two articles
My objective was to build a control that must be simple to use/configure, provide useful feature set and should be similar to the Ajax Control Toolkit Calendar control.
Using the code
To use the control:
1. Add a reference to the control assembly Ajaxified.dll. Also add the assembly to the toolbox.
The TimePicker control will be aded to the toolbox.
2. Add a textbox control whom you need to extend to behave as a Time Picker. Drag the TimePicker control from the toolbox.
It will add the following page directive and the control on the page.
<%@ Register TagPrefix="Ajaxified" Assembly="Ajaxified" Namespace="Ajaxified" %>
The final markup will be
<asp:TextBox ID="TextBox1" runat="server" Text=""></asp:TextBox>
<Ajaxified:TimePicker ID="TimePicker1" runat="server" TargetControlID="TextBox1"></Ajaxified:TimePicker>
The Time Picker control exposes following properties
Property Name | Type | Comments |
---|---|---|
CloseOnSelection |
boolean |
Specify whether the pop should automatically close when a specific time is selected. The default is false. |
MinuteStep |
Int32 |
Specify the minute interval between two values. The default value is 15 min. |
OnClientShowing |
string |
Client event when the popup starts to open. |
OnClientShown |
string |
Client event when the popup has opened completely. |
OnClientHiding |
string |
Client event when the popup starts to close. |
OnClientHidden |
string |
Client event when the popup is completely closed. |
OnClientSelectionChanged |
string |
Client event when the time selection is done. |
CssClass |
string |
The Css class Name for the control. |
HeaderCssClass |
string |
The Css class Name for the header part. |
TitleCssClass |
string |
The Css class Name for the title text. |
TabCssClass |
string |
The Css class Name for the am/pm tab. |
ItemCssClass |
string |
The Css class Name for the item cell. |
SelectedItemCssClass |
string |
The Css class Name for the item cell that is selected. |
SelectedTabCssClass |
string |
The Css class Name for the tab that is selected. |
The markup illustrating the use of these properties:
<asp:TextBox ID="TextBox2" runat="server" Text=""></asp:TextBox>
<Ajaxified:TimePicker runat="server" TargetControlID="TextBox2"
CssClass="timepicker"
HeaderCssClass="header"
TitleCssClass="title"
ItemCssClass="item"
SelectedItemCssClass="selecteditem"
TabCssClass="tab"
SelectedTabCssClass="selectedtab"
OnClientShowing="clientShowing"
OnClientShown="clientShown"
OnClientHiding="clientHiding"
OnClientHidden="clientHidden"
OnClientSelectionChanged="selectionChanged"
MinuteStep="10"
CloseOnSelection="true">
</Ajaxified:TimePicker>
and to handle the events
<script language="javascript" type="text/javascript">
function clientShowing(sender) {
//sender is reference to the timepicker object
}
function clientShown(sender) {
//sender is reference to the timepicker object
}
function clientHiding(sender) {
//sender is reference to the timepicker object
}
function clientHidden(sender) {
//sender is reference to the timepicker object
}
function selectionChanged(sender) {
alert(sender._selectedTime);
}
</script>
Styling
The basic layout of the control is defined as illustrated in the image below.Each section has a CssName property attached to it to handle all the styling needs for the control. If the user does not assign these properties, the control renders with default style as shown in the introductory image. It is advisable to play only with the color and font schemes to maintain the layout consistency. The demo application contains a Style Sheet to illustrate how to override the default style for the control.
Section Name | Css Property Name |
---|---|
CssClass |
Whole Control. |
HeaderCssClass |
Header. |
TitleCssClass |
Title Text. |
TabCssClass |
AM/PM tab. |
ItemCssClass |
Item Cell. |
SelectedItemCssClass |
Selected Item Cell. |
SelectedTabCssClass |
Selected Tab. |
Validation
The control is also capable of basic input validation.If the user keys in invalid time format, the control will provide a visual cue that something is wrong as shown in the image above.
Points of Interest
This exercise has been of a great value to me, specially when it came to client side scripting. The most important thing I came to learn was how to use javascript in an object oriented way. There were however minor hiccups when trying out in various browsers.
I have tested the component on IE8, Firefox 4 and Chrome. There is an issue in the layout when used in IE7.0 but the whole idea of this exercise was creating an extender control rather than learning about cross browser issues. So I left it out there.
References
Appreciations for these authors for providing such nice examples.
发表评论
1hmcWf ThаА аЂаre is noticeablаАааБТ a ton to realize about thаАабТТаАабТа.
aCrhPW Just Browsing While I was browsing yesterday I noticed a great post about
9fIVoP There as certainly a great deal to find out about this issue. I really like all the points you made.
ToV7HU wow, awesome article post. Really Great.
GQJq6k Its like you read my mind! You seem to know so much about this, like you wrote
uiWfKu I value the blog post.Much thanks again. Will read on
mc0DqO stiri interesante si utile postate pe blogul dumneavoastra. dar ca si o paranteza , ce parere aveti de inchiriere vile vacanta ?.
QSOduk writing is my passion that as why it is quick for me to do post writing in significantly less than a hour or so a
JxMlEL I was recommended this website by my cousin. I am not sure whether this post is written by him as nobody else know such detailed about my problem. You are incredible! Thanks!
YI5Qqp technique of writing a blog. I saved it to my bookmark webpage list and
FBfMyq standard parts you happen to be familiar with but might not know how to utilize properly, along with other unique offerings in the car that ensure it is more hard to.
ZqxUOX Enjoyed every bit of your blog post.Thanks Again. Keep writing.
GUZxBj Useful info. Lucky me I found your site accidentally, and I'm surprised why this accident did not took place in advance! I bookmarked it.
YGnkSV Wonderful site. A lot of helpful information here. I am sending it to some buddies ans also sharing in delicious. And naturally, thank you for your effort!
WRXBvX I'd should examine with you here. Which isn't something I normally do! I take pleasure in studying a post that may make folks think. Additionally, thanks for permitting me to comment!
Hey, thanks for the blog. Great.
Major thanks for the blog post.Thanks Again. Cool.
Very good blog article.Really looking forward to read more. Fantastic.
A big thank you for your blog article.Really looking forward to read more. Really Great.
Thank you ever so for you post.
Major thankies for the blog article.Really looking forward to read more. Great.
Thanks a lot for the blog post.Much thanks again.
This is one awesome blog post.Really looking forward to read more. Much obliged.
Major thanks for the blog article. Really Cool.
Thank you for your article post.Really looking forward to read more. Much obliged.
I truly appreciate this article.Really looking forward to read more. Awesome.
A round of applause for your article.Really thank you! Great.
Really appreciate you sharing this blog post.Really thank you! Fantastic.
Thanks again for the article.Thanks Again. Really Cool.
Major thanks for the article.Thanks Again. Will read on...
Fantastic blog article.Thanks Again. Really Great.
Thank you for your blog article.Much thanks again. Great.
Im thankful for the post.Thanks Again. Great.
Fantastic blog article.Thanks Again. Awesome.
I really enjoy the post.Really thank you! Much obliged.
Very neat blog.Really thank you! Great.
Really informative post.Much thanks again. Great.
Very informative article.Really thank you! Fantastic.
Thanks for the article.Much thanks again. Want more.
Muchos Gracias for your article.Really thank you! Fantastic.
WYnBpW I loved your post.Thanks Again. Really Cool.
Appreciate you sharing, great post.Really thank you! Keep writing.
Very neat post.Really looking forward to read more. Want more.
Wow, great post. Awesome.
Wow, great blog article.Really thank you! Will read on...
Very informative blog.Really looking forward to read more. Really Great.
Hey, thanks for the blog article.Really thank you! Want more.
Say, you got a nice post.Really looking forward to read more.
Enjoyed every bit of your article post.Thanks Again. Great.
I really liked your article.Thanks Again. Awesome.