ASP。網

ASP。網- Event Handling

ASP。網- Event Handling

ASP。網provides us the feature to handle the events in web Form. It allows us to implement event-based in our application. Suppose we have a button on our web page and we have to add action to that button. We can easily do this by writing a click event for the button. This can be done on both client and server-side. In ASP.NET web form, events associated with server control originates on the client-side but are resolved on the webserver by ASP.NET.

在ASP。網web form follows a pattern of handling events. All events pass two arguments first one is the object that raised the event and the other one is the object containing information about the event.

應用程序和會話事件

  • 應用程序啟動—在應用程序啟動時引發
  • 應用程序結束—應用程序結束時引發
  • 會話啟動——當用戶第一次請求時引發
  • 會話結束——當用戶希望結束會話時將引發此異常

頁麵控製事件

  • 數據綁定——當控件綁定到數據庫時將引發此問題
  • dispose——當釋放控製時將引發此異常
  • 在拋出未處理的異常時調用的錯誤
  • 在初始化控件時調用
  • 加載——當加載頁麵上的控件時將引發此異常
  • 在呈現頁麵時調用PreRender
  • 當請求和響應完成後,從內存中卸載/釋放控件時調用Unload

事件處理是使用控件完成的

ASP。NET擁有在用戶操作時觸發的類。例如,如果單擊表單上可用的提交按鈕,將會觸發一些操作。

按鈕控件的ASP標記:

代碼:

 "

事件處理示例


EventHandling.aspx.cs


代碼:

EventHandling.aspx

<%@ Page Language=" c# " AutoEventWireup="true" CodeBehind="EnventHandling.aspx.cs" Inherits="Demo_1. "EnventHandling " % > < !DOCTYPE html>   




    



Baidu
.


Baidu
map

EventHandling.aspx.cs

使用係統;使用System.Collections.Generic;使用來;使用包含;使用System.Web.UI;使用System.Web.UI.WebControls;命名空間Demo_1{公共部分類EnventHandling: System.Web.UI.Page{受保護的void Page_Load(對象發送者,EventArgs e) {lablemessage. page。Text += "頁麵加載事件。< br / >”;if (Page.IsPostBack){標簽消息。Text += "Page post back event.
"; } } protected void Page_Init(object sender, EventArgs e) { lablemessage.Text += "Page initialization event.
"; } protected void Page_PreRender(object sender, EventArgs e) { lablemessage.Text += "Page prerender event.
"; } protected void button click(object sender, EventArgs e) { lablemessage.Text += "Button click event.
"; } } }

輸出

Baidu
map