知识大全 ASP.NET整个Postback程序处理的过程

Posted 过程

篇首语:不要以为你的努力可以一劳永逸,权当做你始终一无所有。本文由小常识网(cha138.com)小编为大家整理,主要介绍了知识大全 ASP.NET整个Postback程序处理的过程相关的知识,希望对你有一定的参考价值。

ASP.NET整个Postback程序处理的过程  以下文字资料是由(全榜网网www.cha138.com)小编为大家搜集整理后发布的内容,让我们赶快一起来看一下吧!

  ASP NET整个Postback程序处理的过程

  我们知道 无论是ASP NET x 甚至是以后的版本 ASP NET最终Render到Client端通过浏览器浏览的都是一样 一个单纯的HTML Client通过 Submit Form的方式将填入Form的数据提交给Server进行处理 我们现在来看看ASP NET整个Postback程序处理的过程

  首先我们通过一个Sample来看ASP NET如何处理一个通过Click一个Button引起的Postback 下面是Web Page的HTML

  <%@ Page Language= C# AutoEventWireup= true CodeFile= Default aspx cs Inherits= _Default %>

  <!DOCTYPE PUBLIC //W C//DTD XHTML Transitional//EN transitional dtd >

  < 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>

  </>

  很简单 定义了 个Button 分别注册了他们的两个Event Click和Command 个Button的Command Event Hander是一样的 Button_Command 通过指定的CommandArgument来让Event Handler判断到底是哪个Button触发了Command Event

  下面是Code Behind

  using System;

  using System Data;

  using System Configuration;

  using System Web;

  using System Web Security;

  using System Web UI;

  using System Web UI WebControls;

  using System Web UI WebControls WebParts;

  using System Web UI HtmlControls;

  public partial class _Default : System Web UI Page

  

  protected void Page_Load(object sender EventArgs e)

  

  

  protected void Button _Click(object sender EventArgs e)

  

  string message = string Format( The event of is fired Click Button );

  this LabelMessage Text = message;

  

  protected void Button _Click(object sender EventArgs e)

  

  string message = string Format( The event of is fired Click Button );

  this LabelMessage Text = message;

  

  protected void Button _Click(object sender EventArgs e)

  

  string message = string Format( The event of is fired Click Button );

  this LabelMessage Text = message;

  

  protected void Button_Command(object sender CommandEventArgs e)

  

  string message = string Format( The event of is fired Command e CommandArgument);

  this LabelMessage Text += ; + message;

  

  

cha138/Article/program/net/201311/12069

相关参考