不同执行顺序的目的:Init()和Load() [英] Purpose of different order of execution: Init() and Load()

查看:75
本文介绍了不同执行顺序的目的:Init()和Load()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

 •包含
的主页面•ASPX包含
的Web表单页面•页面内的Web用户控件,其中包含
•用于在button_click事件中触发某些代码的按钮

Init事件将触发(内部最多到最外部)

  aspx .page Begin Init 
- >内部用户控件Page_Init
- >内页母页Page_Init
- >内部生命周期页面page_Init
aspx.page End Init

并且加载事件将触发

  aspx.page开始加载
- >内部生命周期页面Page_Load
- >内页主页Page_Load
- >内部用户控件Page_Load
aspx.page结束加载

为什么ASP.NET框架支持不同执行顺序在 Load() Init()。这是采访中提出的问题。我不知道



请求您的帮助。

解决方案

我建议您阅读 ASP.NET页面生命周期



这两个具有不同的用途,因此执行顺序不同。



初始化:


在页面初始化期间,页面上的控件可用,并且每个控件的UniqueID属性都被设置。主页和主题也适用于页面(如果适用)。如果当前请求是回发,则回发数据尚未加载,控件属性值尚未恢复为视图状态的值。


加载:


在加载期间,如果当前请求是回发,控件属性将加载从视图状态恢复的信息,控制状态。


此外,您需要了解关系关系(主页面实际上包含在内容页面,而不是其他方式)和两个完整的生命周期






所以,在init期间,用户控件需要初始化首先,它们可用于其容器,然后是主页面,因此其内容可用于内容页面,然后页面本身,完成控制层次结构初始化。



在加载过程中,发生相反的情况,因为现在所有的回发数据已经被设置并且所有的控件已经准备就绪并且可以触发其不同的事件。顶部容器,内容页面首先加载(因为它可以更改母版页和用户控件),然后是主页面,最后加载叶子控件。


During a recent interview the following question was asked.

• A Master page which contains 
   • An ASPX web form page which contains 
      • A Web User Control inside the page which contains 
         • A button to fire some code in a button_click event

The Init Event will fire (Inner Most to Outer Most)

aspx.page Begin Init
   –> Inside user control Page_Init 
   –> Inside master page Page_Init
   –> Inside lifecycle page Page_Init 
aspx.page End Init

and Load Event will fire

aspx.page Begin Load
  –> Inside lifecycle page Page_Load
  –> Inside master page Page_Load
  –> Inside user control Page_Load 
aspx.page End Load

Why does ASP.NET framework support different execution order in Load() and Init().This was the question asked in interview.I have no idea about what the interviewer expecting from me.

I request your help please.

解决方案

I suggest reading about the ASP.NET page life cycle.

The two have different purposes, hence different execution order.

Initialization :

During page initialization, controls on the page are available and each control's UniqueID property is set. A master page and themes are also applied to the page if applicable. If the current request is a postback, the postback data has not yet been loaded and control property values have not been restored to the values from view state.

Load:

During load, if the current request is a postback, control properties are loaded with information recovered from view state and control state.

Additionally, you need to understand the relationship between master pages and content pages (master pages are in fact included in the content pages, not the other way around) and the complete life cycle of both.


So, during init, the user controls need to be initialized first, so they are available to their container, then the master page so it's contents are available to the content page and then the page itself, completing the control hierarchy initialization.

During load, the opposite happens, as now all postback data has been set and all the controls are ready and can fire their different events. The top container, the content page loads first (as it can change the master page and user controls), then the master page and in the end the leaf controls.

这篇关于不同执行顺序的目的:Init()和Load()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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