简单的DateTime程序没有显示日期?

时间:2014-12-18 16:07:50

标签: c# asp.net

我是Asp.NET的新手

我正在尝试使用此程序显示日期:

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="inde.aspx.cs" Inherits="WebApplication1.inde" %>

<script runat="server">

    void Page_Load()
    {
        lblServerTime.Text = DateTime.Now.ToString("hh:mm:yyyy");
    }

</script>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
    <title>First Page</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>

    The current date and time is:

    <asp:Label
        id="lblServerTime"
        Runat="server" />

    </div>
    </form>
</body>
</html>

但它除此之外什么都没显示:

输出:

The current date and time is:  

请帮助!!

当然,我们将非常感谢帮助!

3 个答案:

答案 0 :(得分:2)

请尝试将Page_Load方法放在文件inde.aspx.cs

后面的代码中

答案 1 :(得分:1)

您可以这样做:

<asp:Label ID="lblServerTime" runat="server" ><%= System.DateTime.Now %></asp:Label>

答案 2 :(得分:0)

尝试删除:

CodeBehind =“inde.aspx.cs”Inherits =“WebApplication1.inde”

它会起作用。

相关问题