472,794 Members | 2,168 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,794 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 1130
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: erikbower65 | last post by:
Using CodiumAI's pr-agent is simple and powerful. Follow these steps: 1. Install CodiumAI CLI: Ensure Node.js is installed, then run 'npm install -g codiumai' in the terminal. 2. Connect to...
0
linyimin
by: linyimin | last post by:
Spring Startup Analyzer generates an interactive Spring application startup report that lets you understand what contributes to the application startup time and helps to optimize it. Support for...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Sept 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
by: Taofi | last post by:
I try to insert a new record but the error message says the number of query names and destination fields are not the same This are my field names ID, Budgeted, Actual, Status and Differences ...
0
by: Rina0 | last post by:
I am looking for a Python code to find the longest common subsequence of two strings. I found this blog post that describes the length of longest common subsequence problem and provides a solution in...
5
by: DJRhino | last post by:
Private Sub CboDrawingID_BeforeUpdate(Cancel As Integer) If = 310029923 Or 310030138 Or 310030152 Or 310030346 Or 310030348 Or _ 310030356 Or 310030359 Or 310030362 Or...
0
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
0
by: lllomh | last post by:
How does React native implement an English player?
0
by: Mushico | last post by:
How to calculate date of retirement from date of birth

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.