Asp.Net的生命周期? [英] Life cycle of Asp.Net?

查看:76
本文介绍了Asp.Net的生命周期?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Asp.net的生命周期是什么?

What is life cycle of Asp.net?

推荐答案

设置页面

< ASP.NET确定用户的页面请求需要解析和编译,或者呈现要发送的页面的缓存副本。因此,它在页面生命周期开始之前就已经出现了。在此之后,还检查请求是正常请求,回发,跨页回发或回调。一旦HTTP运行时实例化页面类以执行请求,页面构造函数就会创建一个控件树。



事件



PreInit



此事件是页面生命周期的开始。初始化所有页面控件,并根据aspx源代码设置属性。



可以更改或设置主页面,主题

创建或重新创建动态控件

读取或设置配置文件属性值



Init



首先,发生Page对象的Init事件,然后对Page的每个控件发生Init事件。在这个阶段无法获得Viewstate信息。



控件已初始化

主题皮肤应用(如果有的话)

初始化控件属性

InitComplete



此事件用于处理需要完成所有初始化的任务。



PreLoad



此事件在执行Load之前应执行的任何处理之前使用。如果需要在Load事件之前对页面或控件执行处理,请使用此事件。在Page实例引发此事件之前,它会为自身和所有控件加载视图状态,然后处理Request实例中包含的所有回发数据。



加载



在控件中设置属性并建立数据库连接。



控制事件



这些是特定于控件的事件,例如 - Button Click,DropDownIndexChanged等。



加载完成



此事件用于执行需要加载的任务。



PreRender



在此事件中,Page确保创建所有子控件。页面调用EnsureChildControls用于所有控件,包括它自己。每个设置了datasource / databind属性的控件都会调用其数据绑定方法。



SaveStateComplete



此事件发生在viewstate编码并保存为页面和所有控件之后。



渲染



每个ASP.NET控件都有渲染方法,页面实例调用此方法输出控件的标记,在此事件之后,对页面或控件的任何更改都将被忽略。



卸载



卸载事件用于执行清理任务,如关闭数据库连接,关闭打开的文件,完成日志记录或其他请求的任务。首先在页面控制树上和该页面之后为每个控件发生卸载事件。
Setting Up Of the Page

ASP.NET determines that the page request by a user requires to be parsing and compiling or to render cached copy of the page to be sent. Thus it comes very much before the beginning of the page life cycle. After this, it is also checked that request is a normal request, postback, cross-page postback or callback. The page constructor creates a tree of controls as soon as the HTTP runtime instantiates the page class to perform the request.

Events

PreInit

This event is the beginning of the page life cycle. All page controls are initialized and the properties are set according to the aspx source code.

Possible to change or set Master page, themes
Creates or re-creates dynamic controls
Reads or sets Profile property values

Init

First, the Init event for the Page object occurs, then Init event occurs for each control on the Page. Viewstate information is not available at this stage.

Controls have been initialized
Theme skins applied if any
Initialize control properties
InitComplete

This event is used for processing tasks that require all initialization to be complete.

PreLoad

This event is used before performing any processing that should occur before Load. Use this event if you need to perform processing on your page or control before the Load event. Before the Page instance raises this event, it loads view state for itself and all controls, and then processes any postback data included with the Request instance.

Load

Set properties in controls and establish database connections.

Control Events

These are control specific events such as – Button Click, DropDownIndexChanged, etc.

Load Complete

This event is used for performing those tasks which require load has been completed.

PreRender

In this event, Page ensures that all child controls are created. Page calls EnsureChildControls for all controls, including itself. Every control whose datasource/databind property is set calls for its databind method.

SaveStateComplete

This event occurs after viewstate is encoded and saved for the page and for all controls.

Render

Every ASP.NET control has render method and the page instance calls this method to output the control’s markup, after this event any changes to the page or controls are ignored.

Unload

Unload event is used to do cleanup tasks like closing the database connections, closing of the open files, completing logging or other requested tasks. Unload events occurs for each control on page control tree first and after that page.


这篇关于Asp.Net的生命周期?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆