<%
@ Page Language
=
"
c#
"
%>
< script runat = " server " >
/* 你没看错,下一行就是"abcdefg",正是这一行,才让我有机会写出本篇文章^_^;在文中,我把这一行称作"代码陷阱" */
abcdefg // 代码陷阱
void Page_Load(Object src, EventArgs args)
{
if ( !IsPostBack ) NoteLabel.Text = " 请输入您的姓名: " ;
}
void OnNameSubmit(Object src, EventArgs args)
{
string name = f_Name.Value;
NoteLabel.Text = (name == "" ) ? " 姓名不能为空 " : name + " ,您好。欢迎光临! " ;
}
</ script >
< script runat = " server " >
/* 你没看错,下一行就是"abcdefg",正是这一行,才让我有机会写出本篇文章^_^;在文中,我把这一行称作"代码陷阱" */
abcdefg // 代码陷阱
void Page_Load(Object src, EventArgs args)
{
if ( !IsPostBack ) NoteLabel.Text = " 请输入您的姓名: " ;
}
void OnNameSubmit(Object src, EventArgs args)
{
string name = f_Name.Value;
NoteLabel.Text = (name == "" ) ? " 姓名不能为空 " : name + " ,您好。欢迎光临! " ;
}
</ script >
<
html
>
< body >
< form runat ="server" >
< h1 > DllTest - Ex2(例2) </ h1 >
< hr >
< asp :label runat ="server" id ="NoteLabel" style ="color:red; font-weight:bold" />
< input runat ="server" id ="f_Name" size ="8" >
< button runat ="server" onserverclick ="OnNameSubmit" > 确定 </ button >
</ form >
</ body >
</ html >
< body >
< form runat ="server" >
< h1 > DllTest - Ex2(例2) </ h1 >
< hr >
< asp :label runat ="server" id ="NoteLabel" style ="color:red; font-weight:bold" />
< input runat ="server" id ="f_Name" size ="8" >
< button runat ="server" onserverclick ="OnNameSubmit" > 确定 </ button >
</ form >
</ body >
</ html >
现在让我们打开"陷阱",来看看Asp.Net到底返回了什么?
返回的是一个"编译错误"的页面,报告源文件无法通过编译。让我们感兴趣的是该页面最下方的一个名为"显示完整的编译源"的超链接,点击些链接,就能看到这
个由ex2.aspx转换而来的cs源文件("完整的编译源")的完整内容。把这部分"完整的编译源"去掉前面的行号信息和其它的一些编译开关(主要是
#line编译命令),并关闭那个可爱的"代码陷阱"(用//把它注释掉或直接把它delete也行),整理后保存为ex2_aspx.cs:
namespace
ASP
{
using System;
using System.Collections;
using System.Collections.Specialized;
using System.Configuration;
using System.Text;
using System.Text.RegularExpressions;
using System.Web;
using System.Web.Caching;
using System.Web.SessionState;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
/*
1、注意一下类名的构成,如果必要,可以把它改成有意义的名称,例如针对本文,可以改成Ex2Page
2、注意它的基类。Syste.Web.UI.Page实现了IHttpHandler接口,由于要访问Session,所以也实现了IRequiresSessionState接口。
*/
public class ex2_aspx : System.Web.UI.Page, System.Web.SessionState.IRequiresSessionState
{
private static int __autoHandlers;
protected System.Web.UI.WebControls.Label NoteLabel;
protected System.Web.UI.HtmlControls.HtmlInputText f_Name;
protected System.Web.UI.HtmlControls.HtmlButton __control3;
protected System.Web.UI.HtmlControls.HtmlForm __control2;
private static bool __intialized = false ;
private static System.Collections.ArrayList __fileDependencies;
/* 现在可以关掉"陷阱"了 */
// abcdefg
void Page_Load(Object src, EventArgs args)
{
if ( !IsPostBack ) NoteLabel.Text = " 请输入您的姓名: " ;
}
void OnNameSubmit(Object src, EventArgs args)
{
string name = f_Name.Value;
NoteLabel.Text = (name == "" ) ? " 姓名不能为空 " : name + " ,您好。欢迎光临! " ;
}
/* 构造函数 */
public ex2_aspx()
{
System.Collections.ArrayList dependencies;
if ((ASP.ex2_aspx.__intialized == false ))
{
dependencies = new System.Collections.ArrayList();
/*
应该把下面这行注释掉,让DLL成为一个无依赖的独立文件
防止在DLL运行时再次去查找、比较它的"依赖"文件的新旧
*/
// dependencies.Add("W:\\wwwroot\\dlltest\\ex2.aspx");
ASP.ex2_aspx.__fileDependencies = dependencies;
ASP.ex2_aspx.__intialized = true ;
}
}
protected override int AutoHandlers
{
get {
return ASP.ex2_aspx.__autoHandlers;
}
set {
ASP.ex2_aspx.__autoHandlers = value;
}
}
protected System.Web.HttpApplication ApplicationInstance
{
get
{
return ((System.Web.HttpApplication)( this .Context.ApplicationInstance));
}
}
public override string TemplateSourceDirectory
{
get
{
return " /dlltest " ;
}
}
private System.Web.UI.Control __BuildControlNoteLabel()
{
System.Web.UI.WebControls.Label __ctrl;
_ctrl = new System.Web.UI.WebControls.Label();
this .NoteLabel = _ctrl;
_ctrl.ID = " NoteLabel " ;
((System.Web.UI.IAttributeAccessor)(__ctrl))。SetAttribute( " style " , " color:red; font-weight:bold " );
return __ctrl;
}
private System.Web.UI.Control __BuildControlf_Name()
{
System.Web.UI.HtmlControls.HtmlInputText __ctrl;
_ctrl = new System.Web.UI.HtmlControls.HtmlInputText();
this .f_Name = _ctrl;
_ctrl.ID = " f_Name " ;
_ctrl.Size = 8 ;
return _ctrl;
}
private System.Web.UI.Control __BuildControl__control3()
{
System.Web.UI.HtmlControls.HtmlButton __ctrl;
_ctrl = new System.Web.UI.HtmlControls.HtmlButton();
this ._control3 = _ctrl;
System.Web.UI.IParserAccessor _parser = ((System.Web.UI.IParserAccessor)(_ctrl));
_parser.AddParsedSubObject( new System.Web.UI.LiteralControl( " 确定 " ));
_ctrl.ServerClick += new System.EventHandler( this .OnNameSubmit);
return _ctrl;
}
private System.Web.UI.Control __BuildControl__control2()
{
System.Web.UI.HtmlControls.HtmlForm _ctrl;
_ctrl = new System.Web.UI.HtmlControls.HtmlForm();
this ._control2 = _ctrl;
System.Web.UI.IParserAccessor _parser = ((System.Web.UI.IParserAccessor)(_ctrl));
_parser.AddParsedSubObject ( new System.Web.UI.LiteralControl( " \r\n <h1>DllTest - Ex2(例2)< /h1>\r\n <hr>\r\n " ));
this ._BuildControlNoteLabel();
_parser.AddParsedSubObject( this .NoteLabel);
_parser.AddParsedSubObject( new System.Web.UI.LiteralControl( " \r\n " ));
this ._BuildControlf_Name();
_parser.AddParsedSubObject( this .f_Name);
_parser.AddParsedSubObject( new System.Web.UI.LiteralControl( " \r\n " ));
this ._BuildControl_control3();
_parser.AddParsedSubObject( this ._control3);
_parser.AddParsedSubObject( new System.Web.UI.LiteralControl( " \r\n " ));
return _ctrl;
}
private void _BuildControlTree(System.Web.UI.Control _ctrl)
{
System.Web.UI.IParserAccessor _parser = ((System.Web.UI.IParserAccessor)(_ctrl));
_parser.AddParsedSubObject( new System.Web.UI.LiteralControl( " \r\n\r\n<html>\r\n<body>\r\n " ));
this ._BuildControl_control2();
_parser.AddParsedSubObject( this ._control2);
_parser.AddParsedSubObject( new System.Web.UI.LiteralControl( " \r\n</body>\r\n</html>\r\n " ));
}
protected override void FrameworkInitialize()
{
this ._BuildControlTree( this );
this .FileDependencies = ASP.ex2_aspx._fileDependencies;
this .EnableViewStateMac = true ;
}
public override int GetTypeHashCode()
{
return - 11574299 ;
}
}
}
/* 源文件:ex2_aspx.cs 结束 */
{
using System;
using System.Collections;
using System.Collections.Specialized;
using System.Configuration;
using System.Text;
using System.Text.RegularExpressions;
using System.Web;
using System.Web.Caching;
using System.Web.SessionState;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
/*
1、注意一下类名的构成,如果必要,可以把它改成有意义的名称,例如针对本文,可以改成Ex2Page
2、注意它的基类。Syste.Web.UI.Page实现了IHttpHandler接口,由于要访问Session,所以也实现了IRequiresSessionState接口。
*/
public class ex2_aspx : System.Web.UI.Page, System.Web.SessionState.IRequiresSessionState
{
private static int __autoHandlers;
protected System.Web.UI.WebControls.Label NoteLabel;
protected System.Web.UI.HtmlControls.HtmlInputText f_Name;
protected System.Web.UI.HtmlControls.HtmlButton __control3;
protected System.Web.UI.HtmlControls.HtmlForm __control2;
private static bool __intialized = false ;
private static System.Collections.ArrayList __fileDependencies;
/* 现在可以关掉"陷阱"了 */
// abcdefg
void Page_Load(Object src, EventArgs args)
{
if ( !IsPostBack ) NoteLabel.Text = " 请输入您的姓名: " ;
}
void OnNameSubmit(Object src, EventArgs args)
{
string name = f_Name.Value;
NoteLabel.Text = (name == "" ) ? " 姓名不能为空 " : name + " ,您好。欢迎光临! " ;
}
/* 构造函数 */
public ex2_aspx()
{
System.Collections.ArrayList dependencies;
if ((ASP.ex2_aspx.__intialized == false ))
{
dependencies = new System.Collections.ArrayList();
/*
应该把下面这行注释掉,让DLL成为一个无依赖的独立文件
防止在DLL运行时再次去查找、比较它的"依赖"文件的新旧
*/
// dependencies.Add("W:\\wwwroot\\dlltest\\ex2.aspx");
ASP.ex2_aspx.__fileDependencies = dependencies;
ASP.ex2_aspx.__intialized = true ;
}
}
protected override int AutoHandlers
{
get {
return ASP.ex2_aspx.__autoHandlers;
}
set {
ASP.ex2_aspx.__autoHandlers = value;
}
}
protected System.Web.HttpApplication ApplicationInstance
{
get
{
return ((System.Web.HttpApplication)( this .Context.ApplicationInstance));
}
}
public override string TemplateSourceDirectory
{
get
{
return " /dlltest " ;
}
}
private System.Web.UI.Control __BuildControlNoteLabel()
{
System.Web.UI.WebControls.Label __ctrl;
_ctrl = new System.Web.UI.WebControls.Label();
this .NoteLabel = _ctrl;
_ctrl.ID = " NoteLabel " ;
((System.Web.UI.IAttributeAccessor)(__ctrl))。SetAttribute( " style " , " color:red; font-weight:bold " );
return __ctrl;
}
private System.Web.UI.Control __BuildControlf_Name()
{
System.Web.UI.HtmlControls.HtmlInputText __ctrl;
_ctrl = new System.Web.UI.HtmlControls.HtmlInputText();
this .f_Name = _ctrl;
_ctrl.ID = " f_Name " ;
_ctrl.Size = 8 ;
return _ctrl;
}
private System.Web.UI.Control __BuildControl__control3()
{
System.Web.UI.HtmlControls.HtmlButton __ctrl;
_ctrl = new System.Web.UI.HtmlControls.HtmlButton();
this ._control3 = _ctrl;
System.Web.UI.IParserAccessor _parser = ((System.Web.UI.IParserAccessor)(_ctrl));
_parser.AddParsedSubObject( new System.Web.UI.LiteralControl( " 确定 " ));
_ctrl.ServerClick += new System.EventHandler( this .OnNameSubmit);
return _ctrl;
}
private System.Web.UI.Control __BuildControl__control2()
{
System.Web.UI.HtmlControls.HtmlForm _ctrl;
_ctrl = new System.Web.UI.HtmlControls.HtmlForm();
this ._control2 = _ctrl;
System.Web.UI.IParserAccessor _parser = ((System.Web.UI.IParserAccessor)(_ctrl));
_parser.AddParsedSubObject ( new System.Web.UI.LiteralControl( " \r\n <h1>DllTest - Ex2(例2)< /h1>\r\n <hr>\r\n " ));
this ._BuildControlNoteLabel();
_parser.AddParsedSubObject( this .NoteLabel);
_parser.AddParsedSubObject( new System.Web.UI.LiteralControl( " \r\n " ));
this ._BuildControlf_Name();
_parser.AddParsedSubObject( this .f_Name);
_parser.AddParsedSubObject( new System.Web.UI.LiteralControl( " \r\n " ));
this ._BuildControl_control3();
_parser.AddParsedSubObject( this ._control3);
_parser.AddParsedSubObject( new System.Web.UI.LiteralControl( " \r\n " ));
return _ctrl;
}
private void _BuildControlTree(System.Web.UI.Control _ctrl)
{
System.Web.UI.IParserAccessor _parser = ((System.Web.UI.IParserAccessor)(_ctrl));
_parser.AddParsedSubObject( new System.Web.UI.LiteralControl( " \r\n\r\n<html>\r\n<body>\r\n " ));
this ._BuildControl_control2();
_parser.AddParsedSubObject( this ._control2);
_parser.AddParsedSubObject( new System.Web.UI.LiteralControl( " \r\n</body>\r\n</html>\r\n " ));
}
protected override void FrameworkInitialize()
{
this ._BuildControlTree( this );
this .FileDependencies = ASP.ex2_aspx._fileDependencies;
this .EnableViewStateMac = true ;
}
public override int GetTypeHashCode()
{
return - 11574299 ;
}
}
}
/* 源文件:ex2_aspx.cs 结束 */