I’m a very new ASP.NET developer (and web developer at all for that matter.) I want to put together a simple website that has the web server providing a form containing a few controls for setting a timer, and a start button, which when pressed, posts the configuration to the server (for how long the timer is set for.) and also starts the timer in the client, upon expiration, it would also post to the server that this has been done.
If this is easy please explain to me how to go about doing something like this, if this is not easy, or even more so if this is “not a good way to go about this” please explain to me a better architecture or design for this.
As this is a client-side thing, I wouldn’t use ASP.NET 🙂 Obviously it still stands for the server-side, anyway:
<form>with the timer<select>or text-box or something.Sessionstate in case the user refreshes the page. The value should be saved as an absolute UTC date-time value.setTimeout.<form>element which is submitted, causing a POST request to the server with some tag that identifies the client and timer that expired. The server then does another 303 redirect back to the original view, possibly containing a message for the user or something.This is probably the simplist way using modern techniques and avoiding complexities inherent in using AJAX or external frameworks like jQuery or Mootools. Note my use of 303 redirect instead of returning a HTML repsonse to a POST request – this is for the user’s benefit so they never get the browser “Resubmit form?” dialog and also prevents the timer from being reset.
UPDATE:
Why 3xx Responses Are Good:
When a client submits a POST request, the webserver can respond either by returning a response directly, or by doing a 3xx redirect to another page. The problem with providing a response directly is that the content of the response (i.e. the web page) is not “accessible” as far as HTTP is concerned: you cannot retrieve the same content with a GET request. This is why when a user presses F5 or hits Refresh for a POST’d page they get a message-box prompting them (in cryptic language) to resubmit the form, however often if the user resubmits the form they’ll end up breaking the application because their data will be processed twice. This is why ASP.NET WebForms, which its heavy reliance on “postback” is being phased out.
Javascript
The code would look something like this: