ASPNET整个Postback程序处理的过程
我们知道无论是ASPNETx 甚至是以后的版本ASPNET最终Render到Client端通过浏览器浏览的都是一样一个单纯的HTMLClient通过 Submit Form的方式将填入Form的数据提交给Server进行处理我们现在来看看ASPNET整个Postback程序处理的过程
首先我们通过一个Sample来看ASPNET如何处理一个通过Click一个Button引起的Postback下面是Web Page的HTML
<%@ Page Language=C# AutoEventWireup=true CodeFile=Defaultaspxcs Inherits=_Default %>
<!DOCTYPE html PUBLIC //WC//DTD XHTML Transitional//ENtransitionaldtd>
<html xmlns=>
<head runat=server>
<title>Test Page</title>
</head>
<body>
<form id=form runat=server>
<div>
<asp:Label runat=server ID=LabelMessage ForeColor=red></asp:Label>
</div>
<div>
<asp:Button runat=server ID=Button Text=Button
OnClick=Button_Click OnCommand=Button_Command
CommandArgument=Button />
<asp:Button runat=server ID=Button Text=Button OnClick=Button_Click
OnCommand=Button_Command CommandArgument=Button UseSubmitBehavior=false />
<asp:Button runat=server ID=Button Text=Button OnClick=Button_Click
OnCommand=Button_Command CommandArgument=Button UseSubmitBehavior=false />
</div>
</form>
</body>
</html>
很简单定义了个Button分别注册了他们的两个EventClick和Command个Button的Command Event Hander是一样的Button_Command通过指定的CommandArgument来让Event Handler判断到底是哪个Button触发了Command Event
下面是Code Behind
using System;
using SystemData;
using SystemConfiguration;
using SystemWeb;
using SystemWebSecurity;
using SystemWebUI;
using SystemWebUIWebControls;
using SystemWebUIWebControlsWebParts;
using SystemWebUIHtmlControls;
public partial class _Default : SystemWebUIPage
{
protected void Page_Load(object sender EventArgs e)
{
}
protected void Button_Click(object sender EventArgs e)
{
string message = stringFormat(The {} event of {} is fired Click Button);
thisLabelMessageText = message;
}
protected void Button_Click(object sender EventArgs e)
{
string message = stringFormat(The {} event of {} is fired Click Button);
thisLabelMessageText = message;
}
protected void Button_Click(object sender EventArgs e)
{
string message = stringFormat(The {} event of {} is fired Click Button);
thisLabelMessageText = message;
}
protected void Button_Command(object sender CommandEventArgs e)
{
string message = stringFormat(The {} event of {} is fired Command eCommandArgument);
thisLabelMessageText += ; + message;
}
}
以上是介绍ASPNET整个Postback程序处理的过程