熱點推薦:
您现在的位置: 電腦知識網 >> 編程 >> .NET編程 >> 正文

ASP.NET整個Postback程序處理的過程

2022-06-13   來源: .NET編程 

  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程序處理的過程


From:http://tw.wingwit.com/Article/program/net/201311/12069.html
    推薦文章
    Copyright © 2005-2022 電腦知識網 Computer Knowledge   All rights reserved.