Expression Web help

Join our community

Visit our Expression Web Forum

Insert the date and time

If you need to add a date and time to an expression web page, you can use some asp.net v2 code. Your page must be an aspx page.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
<head>
<title>My First ASP.NET Page</title>
<script runat="server" language="C#">
protected void Page_Load(object sender, EventArgs e)
{
timeLabel.Text = DateTime.Now.ToString();
}
</script>
</head>
<body>
<p>Hello there!</p>
<p>The time is now:
<asp:Label runat="server" id="timeLabel" /></p>
</body>
</html>

The code

Copy the above code and paste it into a html page. Click on save and name your page. From the file type dropdown, select aspx.

Test your page in a browser.

Styling

You can style the display by either setting the properties in the Tag Properties task pane, or with a CSS class style.

Simply click on the time label in design view and the tag property task pane will display the options open to you. If you want to use a class then click on the CSSClass option which can be found in the appearance section of the tag properties task pane.

Limitations

Using the code provided, has some minor limitations. It provides a snap shot of time (it updates on refresh) and the format is as is. Also it displays the server time, tricky if you host outside your time zone.

See an example here

I suspect there are many ways to format the code but i have not looked into this. However i  would be delighted to open a discussion at our forum.

Microsoft MVP

RSS Icon  RSS

Our forum feed can be found here

Add RSS to Yahoo

Reader not listed? Click here for more options

Expression Web Help RSS
Expression Web Help. Tips and Tricks and tutorials Get our feed now