.NET页面执行顺序测试
测试准备: Alert()函数测试TestRunning.aspx
断点方式测试TestRunning.aspx.cs
页面代码:
-------------------------------------------------------------------
TestRunning.aspx
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="TestRunning.aspx.cs" Inherits=" TestRunning" %>
<!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 id="Head1" runat="server">
alert("title_before");
<title>页面执行顺序测试</title>
<base target="_self" />
<script language="javascript" id="clientEventHandlersJS">
<!--
alert("function_before");
function ip_btn_close_onclick(){ alert("closeButton_clicked"); }//
function ip_btn_document_onclick(){ alert("documentName_clicked"); }
function GetEmployee(){ alert("getEmployeeButton_clicked"); }
function window_onload() { alert("window_onload"); }
function ip_btn_AddFile_onclick(){ alert("addFileButton_clicked"); }
function window_onunload() { alert("window_onunload"); }
--></script>
</head>
<body onload="window_onload()" onunload="window_onunload()">
<form id="form1" runat="server">
<div>
<asp:Panel ID="Panel1" runat="server" Width="600px">
<table>
<tr><td>工程号</td></tr>
<script language="javascript" type="text/javascript">
alert("between_TR");
</script>
<tr><td>设计号</td></tr>
</table>
<script language="javascript" type="text/javascript">
alert("between_TABLE");
</script>
<table>
<tr><td>设计任务</td></tr>
<tr><td>
<script language="javascript" type="text/javascript">
alert("before_igtbl");
</script>
<igtbl:UltraWebGrid ID="dg_Data">
</igtbl:UltraWebGrid>
</tr>
</table>
</asp:Panel>
<script language="javascript" type="text/javascript">
alert("between_ip_hid_information");
</script>
<script language="javascript">
<!--
if(window.document.all("ip_hid_information").value != "")
{
window.alert(window.document.all("ip_hid_information").value);
window.document.all("ip_hid_information").value = "";
}
-->
</script>
</form>
</body>
</html>
=======================================================================================
TestRunning.aspx.cs
using System;
public partial class ProjectCreate : Page
{
l (1) protected long UserId = 0;
protected string pm_rowid = "";
protected string action = "add";
ProjectPhaseBO PPBO;
protected void Page_Load(object sender, EventArgs e)
{
PFBO = new ProFileInfoBO();
l (2) currentUserId = UIUtility.GetUserId();
this.ip_hid_principalid.Value = UserId.ToString();
action = Request.QueryString["action"];
if (!this.IsPostBack)
{
CreateDropDownList_Phase();
ip_btn_close.Visible = false;
l (3) pm_rowid = Request.QueryString["pm_rowid"];
this.ip_hid_projectid.Value = pm_rowid;
if (pm_rowid !=null && pm_rowid.Length > 0 )
{
if (action.Equals("edit") || action.Equals("view"))
{
loadProjectInfo(pm_rowid);
}
setButtonsEnable();
}
}
l (4)dg_Data.DataSource = CreatView();
try
{
dg_Data.DataBind();
}
catch (System.Exception myEx)
{
dg_Data.DataBind();
}
}
protected void loadProjectInfo(string projectid)
{
l (6)
}
protected void btn_add_Click(object sender, EventArgs e)
{
l (7)
bool bEdit = false;
if (action != null)
{
if (action.Equals("edit"))
bEdit = true;
}
if (bEdit) { }
else{ }
}
protected void Button1_Click(object sender, EventArgs e)
{
l (8)
}
protected void ip_btn_close_ServerClick(object sender, EventArgs e)
{
}
protected void dg_Data_InitializeRow(object sender, Infragistics.WebUI.UltraWebGrid.RowEventArgs e)
{
l (9)
}
Page_Load包括2,[3],4(9)
操作与结果:
|
执行动作(次序) |
Alert---用A表示 |
断点----用O表示 |
备注 |
|
新建(1) |
0(1)---outside Page_Load()
A(window_onload)---此Alert()在<body>中 |
该页面中包含了下拉框,内容来于数据库 注意:O(4)后面没有执行O(9),即没有执行dg_Data_InitializeRow(初始化dg_Data中的行),因为DataSource没有数据 ??? 为什么window_onload最后执行 |
|
|
选择员工(2) |
A(getEmployeeButton_clicked)---只弹出提示框 |
||
|
保存(3) |
0(1) |
数据填写完后保存。保存按钮指向函数btn_add_Click() ??? 为什么 O(9)还要执行? window_onload最后执行 |
|
|
上传资料(4) |
A(addFileButton_clicked)---弹出提示框确定后弹出上传文件页面 |
保存后紧接着上传资料 |
|
|
上传成功后关闭(5) |
0(1)---状态栏中的进度条迈进… |
关闭时,被弹出页面重新提交,重新加载一次 执行dg_Data.DataBind()时调用。只有一项资料,只执行一次。dg_Data_InitializeRow() ??? 为什么 还要执行 window_onunload |
|
|
启动流程(6) |
0(1)---状态栏中的进度条迈进…页面非空白 |
执行dg_Data.DataBind()时调用dg_Data_InitializeRow(),只有一项资料,只执行一次。 启动流程指向函数Button1_Click() |
|
|
修改(首次) |
0(1)---outside Page_Load(),父页面状态不变 |
点击链接执行相应记录修改 |
|
|
关闭 |
A(closeButton_clicked)---弹出提示框,父页面无状态条 |
||
总结:
1. 第一次执行指:从其它页面首次调用该页面时。
2. 出现页面后,不管是点击了保存还是修改按钮,或者被弹出的子页面返回一个要求其重新提交的命令,都不会执行IsPostBack里面的代码
3. 点击有处理函数的按钮时,总是要先执行Page_Load(),再执行相应处理函数
4. *.aspx页面总是最后执行的,*.aspx.cs总是先执行

浙公网安备 33010602011771号