Forums / General Discussions / How to get a timestamp on a document- one that doesn't change

How to get a timestamp on a document- one that doesn't change

2 posts, 0 answered
  1. Beth Grabo
    Beth  Grabo avatar
    6 posts
    Registered:
    02 Mar 2010
    23 Nov 2011
    Link to this post
    Hi all.  Trying to set a timestamp on our Emergency Status page so that when we update it, we can have a date and time of when it was last updated- something the public finds useful.  I am successful in setting a label with the current date and time- however the date/time value keeps changing with every refresh of the page.  How to make it timestamp at the time of saving and/or publishing my page?  Any suggestions?  Would prefer it "set" when I save the page in Sitefinity.  Here is my code:

    <%@ Control Language="C#" AutoEventWireup="true" CodeFile="updatedDate.ascx.cs" Inherits="UserControls_Custom_updatedDate" %>
     
    <div class="coop_updatedDate">
    <asp:label ID="lbl1" runat="server"></asp:label>
    </div>
     
     and here is the .cs 
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.Configuration;
     
     
    public partial class UserControls_Custom_updatedDate : System.Web.UI.UserControl
    {
        protected void Page_Load(object sender, EventArgs e)
        {
        if (!Page.IsPostBack)
          {
            DateTime now = DateTime.Now; 
            lbl1.Text = "Updated: " + now.ToString(); 
              }
        }
    }
  2. Lubomir Velkov
    Lubomir Velkov avatar
    688 posts
    Registered:
    03 Nov 2014
    25 Nov 2011
    Link to this post
    Hi Beth Grabo,

    I'm not quite sure I understand what you need. If you need a fixed time you could use the DateCreated property of a published page - this field gets its value when you create the page and never changes after that. The code that you use for the label is normally to get its value updated after every reload of the page, because you get DateTime.Now and it is different every time. You could create a Session variable with the current time and check if there is already such variable and if there is simply read its value.

    Best wishes,
    Lubomir Velkov
    the Telerik team
    Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
2 posts, 0 answered