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>