You are not logged in.

#1 22 Jan 2008 2:23 am

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

ASP.NET equivalent of a PHP/JS script

How can I make an 2.0 equivalent of the PHP code mentioned here?

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

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

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



#2 22 Jan 2008 8:27 am

From: Dallas TX
Registered: Jun 2006
Posts: 529

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

actually already has something like this built in. pages contain a viewstate, which is used by the engine to validate posted info for validity (like was this form submitted by the proper aspx page, and so on). 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:


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
            DateTime timestamp = (DateTime)ts;

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



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