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

查看:86
本文介绍了不同的顺序执行的目的: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

Init事件将触发(内心最外层到最)

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

和加载事件将触发

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

为什么ASP.NET框架支持不同的执行顺序加载()的init()。这是在interview.I问的问题没有关于面试官从我期望什么想法。

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.

我请求你的帮助,请。

推荐答案

我建议阅读有关 ASP。 NET页面生命周期

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

The two have different purposes, hence different execution order.

初​​始化:

在页初始化,网页上的控件可与每个控件的UniqueID属性被设置。如果适用母版页和主题也被应用到该页面。如果当前请求是回发,回发数据尚未加载,并且控件属性值尚未恢复到值从视图状态。

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.

负载:

在负荷,如果当前请求是回发,控件属性加载来自视图状态和控件状态恢复的信息。

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

此外,你需要了解的<一个href=\"http://stackoverflow.com/questions/3716734/what-is-the-relation-between-a-content-page-and-master-page-in-terms-of-oop\">relationship母版页和内容页之间(其实都是包含母版页的内容页面,而不是其他方式)和<一个href=\"http://blogs.thesitedoctor.co.uk/tim/2006/06/30/Complete+Lifecycle+Of+An+ASPNet+Page+And+Controls.aspx\">complete无论的生命周期。

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()和负荷()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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