//html页面代码
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
<%--VS2013版本 支持:HTML5--%>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Label ID="labTime" runat="server"></asp:Label>//添加一个Label 控件
</div>
</form>
</body>
</html>
===========================================================================
//
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls; //系统默认的命名空间
public partial class _Default : System.Web.UI.Page
{
/// <summary>
/// 加载数据 protected
/// </summary>
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack) { GetTime(); } //IsPostBack判断程序是否是首次加载
}
/// 具体返回值的方法
/// </summary>
public int Num(int a, int b)
{
return a + b;
}
/// <summary>
/// 获取本地时间,并赋给Label
/// </summary>
public void GetTime()
{
this.labTime.Text = System.DateTime.Now.ToString();
}
}