咱理解的都注释到WebForm1.aspx.cs的这段代码里去了。在aspx页面中,添加<%=this.GetType()%>最终也能得到“ASP.aspxwebform_webform1_aspx”这个子类名,也说明了<%%>中的代码被编译到子类那里去执行了。
按课件上的概括,aspx就是帮我们封装了很多东西,原理上和自己用ashx拼接模板页差不多。
namespace WebApplication1.ASPXWebForm
{
//.aspx.cs与.aspx.designer.cs一起组成WebFrom1这个类
//.aspx.designer.cs中以protected修饰其中声明的变量使得其子类可以访问
public partial class WebForm1 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
Response.Write(this.GetType() + "<br/>");//ASP.aspxwebform_webform1_aspx
Response.Write(this.GetType().Assembly.Location + "<br/>");
Response.Write(this.GetType().BaseType + "<br/>");//WebApplication1.ASPXWebForm.WebForm1
Response.Write(this.GetType().BaseType.Assembly.Location + "<br/>");
//收到request后先运行Page_Load,然后在内部基于aspx的内容动态编译了一个WebForm1的子类,然后子类负责拼接出response
//关于控件,designer中runat="server"的各类控件被转化为对应的原生标签
//其在aspx中的值的初始化赋值在动态编译的WebForm1的子类代码中进行
//经过运算后,控件对象再被解释成html代码拼接进response
}
}
}