You are not logged in.

#1 22 Jan 2008 2:23 am

azzlack
Senior Member
From: Bergen, Norway
Registered: Jan 2008
Posts: 26
Website

ASP.NET equivalent of a PHP/JS script

How can I make an ASP.net 2.0 equivalent of the PHP code mentioned here? http://15daysofjquery.com/examples/contact-forms/

The JS code is easy enough. I just don't know how to convert the code from PHP to ASP.net ...

Last edited by azzlack (22 Jan 2008 2:24 am)


Web Developer and Designer.
Currently studying for Bachelor of Computer Science degree ...

Offline

 

#2 22 Jan 2008 8:27 am

MadHatter
Administrator
From: Dallas TX
Registered: Jun 2006
Posts: 529
Website

Re: ASP.NET equivalent of a PHP/JS script

actually asp.net already has something like this built in. 

asp.net pages contain a viewstate, which is used by the asp.net engine to validate posted info for validity (like was this form submitted by the proper aspx page, and so on).  asp.net page "controls" (which are the various components of a .net web page which can be nested fairly deep inside the page) also use it to save their state.

what you can do there is store a DateTime object in the viewstate, and on postback, you can check to see whether the date listed in the viewstate falls within some pre-determined time span.

it would look something like this:

Code:

public partial class _Default : System.Web.UI.Page {
    TimeSpan timestampThreshold = new TimeSpan(0, 0, 5, 0, 0);
    protected void Page_Load(object sender, EventArgs e) {
        if (IsPostBack) {
            object ts = ViewState["TimeStamp"];
            if (ts == null) { // Invalid post back
                return;
            }
            DateTime timestamp = (DateTime)ts;

            if (DateTime.Now.Subtract(timestamp) >= timestampThreshold) { // took too long
                return;
            }
        }
        ViewState["TimeStamp"] = DateTime.Now;
    }
}

Offline

 



© 2003 - 2017 NullFX
Creative Commons Attribution-NonCommercial-ShareAlike 3.0 License