473,387 Members | 1,897 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 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 1145
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 =
@"^((0?[1-9]|1[012])(:[0-5]\d){0,2}(\s[apAP][mM]|[apAP][mM])?)$|^([01]\d|2[0-3])(:[0-5]\d){1,2}$";
return Regex.IsMatch(text,strTimeFormat);
}

Best of luck...Chuck

Jul 21 '05 #2
BillG,

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,

Cor
Jul 21 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: IIS的响应时间问题,急!!!多谢无 | last post by:
i distribute a website on IIS which is programmed with C# HttpHandler,then i pragram a Winform client to send empty call to the website and record the time that the call return to client. when the...
0
by: Andrew | last post by:
Hi, Until now, I have used a single webform for my web app, and everything's been OK. Now, I've decided to create a main menu webform. So, I've got two webforms. Using Visual Studio .NET (with...
3
by: sparks | last post by:
I am building a web ap and have a webform1 an agreement.cs and a files.cs going to an access database I am not having problems reading or writing to the database but I have hit a snag on how to keep...
0
by: Cabral | last post by:
Hi I creating object in run-time and render the webform, but when I want drop this object I don´t render the page without this object, but in next autopostback of the webform is render correct ...
3
by: BillG | last post by:
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...
0
by: jasonwong | last post by:
Hi, I was wondering if anyone knows of a way to utilize the Runtime Parser to parse a text box filled with user input code. The user will be inputting HTML and data markup into a textbox that...
1
by: yasin | last post by:
is it possible inputting characters from keyboard by codes.or can we use assemly interrupts in asp.net to press keyboard buttons by code.
0
by: yasin | last post by:
is it possible inputting characters from keyboard by codes.or can we use assemly interrupts in asp.net to press keyboard buttons by code.
5
by: =?Utf-8?B?UGF1bA==?= | last post by:
Hi I have start web form and when the user clicks a button (server.transfer) they are directed to the second webform. I was wondering if there is a way to create an instance of the first webform...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.