WebForm 运行原理

创建一个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”的控件都编译成后台页面对象的属性。


 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值