现在的位置: 首页 > 综合 > 正文

WebForm 运行原理

2013年08月08日 ⁄ 综合 ⁄ 共 992字 ⁄ 字号 评论关闭

创建一个WebForm ,在前台放入一个文本框,后台运行的时候给文本框赋值。

前台代码:

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

<!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 runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
    <input type="text" ID="txtName" runat="server" />
    </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 FisrtWebForm : System.Web.UI.Page
{
    private string txtNameVlue="Hello WebForm";
    protected void Page_Load(object sender, EventArgs e)
    {
        this.txtName.Value=txtNameVlue;//给前台文本框赋值
        Response.Write(this.GetType().Assembly.Location + "<br/>");//得到程序编译后的路径

    }
}

运行结果:

 

反编译后的前台页面类代码:

反编译后的后台页面类代码:

运行结果分析:

1.程序运行的时候前台页面aspx和后台代码aspx.cs都编译成两个类,并且前台页面类继承与后台页面类。

2. 为什么后台页面可以用This.访问到前台的控件?

由于前台页面只要是runat=“Server”的控件都编译成后台页面对象的属性。

 

抱歉!评论已关闭.