vs2012,文件,新建,网站,名称为work002.

添加,新建项,web窗体,保留勾选《将代码单独保存在文件中》。

default.aspx

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>

<!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:Button ID="Button1" runat="server" Text="Button" OnClick="Button1_Click" />
        <br />
        <asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
    </div>
    </form>
</body>
</html>

你会发现,页面头部 @Page 后,多了一些设置,比如codefile代码文件=“谁” inherits继承=“谁”。

defalut.aspx.cs

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
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        Label1.Text = "点击后的时间是" + DateTime.Now.ToString();
    }
}

后台代码页面,说明_Default继承与Page类,并且类中指明Partial,说明我是类的一部分。

这样做的意图,就是前台页面设计可以由前端负责,后台代码可以由后端负责,只要控件名称一致,可以分开开发,合并一处时,只需要把@Page的配置项输入正确,

就可以确保程序正常运行。

这种分离,实际效果不好,一般我们看到的,基本都是一个人全部搞定。