471,347 Members | 1,759 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,347 software developers and data experts.

Inputting Time on a Webform

I am looking for an example of how to display a text box and prompt the user
for a time ex. 9:00 am. I would have a start time and an end time and then I
would take the difference to give me the duration of the event. I would like
to provide the user with the least opportunity for screwing up on entering
the time.
Jul 21 '05 #1
2 1084
BillG, Just use a normal asp.net text box and a submit button. In the
page_load event use the following:

try {
DateTime dt = DateTime.Parse(this.TextBox1.Text);
// if you get here, it's a date/time value
catch {
// if you get here, the user did not enter anything that could be construed
as a time

Now, once you get past these basics. You can use a custom validator that
calls the following:

private bool IsTime(string text)
String strTimeFormat =
return Regex.IsMatch(text,strTimeFormat);

Best of luck...Chuck

Jul 21 '05 #2

This is not easy. You need the localized culture of your client. I have
never seen a straight method to get that. You can get the language using the
servervariables. However AFAIK not the culture. Therefore AFAIK you can only
use this, when you are sure that your pages are localy used. And than it is
just converting back from the textbox to datetime and compare those with the
time with what you want to compare it.

I hope this helps,

Jul 21 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by IIS的响应时间问题,急!!!多谢无 | last post: by
reply views Thread by Andrew | last post: by
reply views Thread by Cabral | last post: by
3 posts views Thread by BillG | last post: by
reply views Thread by jasonwong | last post: by
5 posts views Thread by =?Utf-8?B?UGF1bA==?= | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.