只有 page_load和page_init这些可以autoeventwireup

RenderControl只提供override

public override void RenderControl(HtmlTextWriter writer)
{
base.RenderControl(writer);
LogUtil.CreateLog(LogLevel.Message, "Page_RenderControl in ChangeMyPassword");
}

asp.net: what's the page life cycle order of a control/page compared to a user contorl inside it?

You should look at this ASP.NET Page Life Cycle Overview and this

Page: PreInit
Control: Init
Page: Init
Page: InitComplete
Page: PreLoad
Page: Load
Control: Load
Page: LoadComplete
Page: PreRender
Control: PreRender
Page: PreRenderComplete
Page: SaveStateComplete
Page: RenderControl
Page: Render
Control: RenderControl
Control: Unload
Control: Dispose
Page: Unload
Page: Dispose

ASP.NET Application and Page Life Cycle

https://www.codeproject.com/Articles/73728/ASP-NET-Application-and-Page-Life-Cycle

Page Init

This event happens in the ASP.NET page and can be used for:

  • Creating controls dynamically, in case you have controls to be created on runtime.
  • Any setting initialization.
  • Master pages and the settings.

In this section, we do not have access to viewstate, postedvalues and neither the controls are initialized.

Page Load

In this section, the ASP.NET controls are fully loaded and you write UI manipulation logic or any other logic over here.

This is the place where you will put any logic you want to operate on the controls. Like flourishing a combobox from the database, sorting data on a grid, etc. In this event, we get access to all controls, viewstate and their posted values.

PreRender

If you want to make final changes to the UI objects like changing tree structure or property values, before these controls are saved in to view state.

Render

If you want to add some custom HTML to the output this is the place you can.

It’s now time to send the output to the browser. If you would like to make some changes to the final HTML which is going out to the browser, you can enter your HTML logic here.

中文版的

asp.net页面事件执行顺序(轉)

Page life cycle with user control

FAQ: Sequence that events are raised for Pages, UserControls, MasterPages and HttpModules

Understanding the Page Life Cycle can be very important as you begin to build Pages with MasterPages and UserControls.

Does the Init event fire first for the Page, the MasterPage or the UserControl? 
What about the Load event?

If you make an incorrect assumption about the sequence that these
events fire, then you may end up with a page that simply doesn't behave
the way you had anticipated.

By running a simple test, we can see exactly when each event fires. 
Our test setup is composed of a Page, MasterPage, UserControl, Nested
UserControl and Button control as follows:

  • The Page is tied to the MasterPage
  • The UserControl is on the Page
  • The Nested UserControl is on the UserControl
  • The Button is on the Nested UserControl.
  • Clicking the Button calls the Page.DataBind method

Each event on these controls has been set to call
Debug.WriteLine as each event is raised.  In addition to the events that
get raised for regular pages, I've also set up an HttpModule and wired
up all of those events as well. The results in the Debug output
window of running this page and Clicking the Button
are as follows:

BeginRequest - HttpModule
AuthenticateRequest - HttpModule
PostAuthenticateRequest - HttpModule
PostAuthorizeRequest - HttpModule
ResolveRequestCache - HttpModule
PostResolveRequestCache - HttpModule
PostMapRequestHandler - HttpModule
AcquireRequestState - HttpModule
PostAcquireRequestState - HttpModule
PreRequestHandlerExecute - HttpModule

PreInit - Page

Init - ChildUserControl
Init - UserControl
Init - MasterPage
Init - Page

InitComplete - Page

LoadPageStateFromPersistenceMedium - Page

ProcessPostData (first try) - Page

PreLoad - Page

Load - Page
Load - MasterPage
Load - UserControl
Load - ChildUserControl

ProcessPostData (second try) - Page

RaiseChangedEvents - Page
RaisePostBackEvent - Page

Click - Button - ChildUserControl

DataBinding - Page
    DataBinding - MasterPage
    DataBinding - UserControl
    DataBinding - ChildUserControl

LoadComplete - Page

PreRender - Page
PreRender - MasterPage
PreRender - UserControl
PreRender - ChildUserControl

PreRenderComplete - Page

SaveViewState - Page
SavePageStateToPersistenceMedium - Page
SaveStateComplete - Page

Unload - ChildUserControl
Unload - UserControl
Unload - MasterPage
Unload - Page

PostRequestHandlerExecute - HttpModule
ReleaseRequestState - HttpModule
PostReleaseRequestState - HttpModule
UpdateRequestCache - HttpModule
PostUpdateRequestCache - HttpModule
EndRequest - HttpModule
PreSendRequestHeaders - HttpModule
PreSendRequestContent - HttpModule

I hope that you will find this information useful.

Complete Lifecycle of an ASP.Net page and controls

自己做的postback和事件的顺序测试

第一次加载出页面的时候

[INFO] 2019-05-16 10:52:30.026+08:00 - OnInit fired in login page - [6]

[INFO] 2019-05-16 10:52:30.031+08:00 - Page_Init fired in login page - [6]

[INFO] 2019-05-16 10:52:30.037+08:00 - Page_Load fired in login page - [6]

点击登录按钮之后,触发了post back,先加载Init,然后是Load,最后才是按钮click事件绑定的方法

[INFO] 2019-05-16 10:54:03.763+08:00 - OnInit fired in login page - [7]

[INFO] 2019-05-16 10:54:03.764+08:00 - Page_Init fired in login page - [7]

[INFO] 2019-05-16 10:54:03.767+08:00 - Page_Load fired in login page - [7]

[INFO] 2019-05-16 10:54:03.770+08:00 - btnLogin_Click fired in login page - [7]

自己做的page和control的事件顺序测试

user control中的代码

public ChangeMyPassword()
{
Init += ChangeMyPassword_Init;
}

这个是优先注册的

private void ChangeMyPassword_Init(object sender, EventArgs e)
{

LogUtil.CreateLog(LogLevel.Message, "ChangeMyPassword_Init");
}

下面这个是被动注册的,通过autoeventwireup=true延迟绑定的。所以执行顺序在,这个在上面那个后面

protected void Page_Init(object sender, EventArgs e)
{
LogUtil.CreateLog(LogLevel.Message, "Page_Init in user control");
}

[INFO] 2019-05-16 13:30:07.330+08:00 -program /LM/W3SVC/4/ROOT/MyApplication-2-132024582037055218 started. - [1]

[INFO] 2019-05-16 13:30:11.963+08:00 - ChangeMyPassword_Init - [10]

[INFO] 2019-05-16 13:30:11.967+08:00 - Page_Init in user control - [10]

[INFO] 2019-05-16 13:30:11.994+08:00 - Page_Init in login page - [10]

web forms page和control的生命周期life cycle交互,以及page生命周期中每个event中需要做什么事情的更多相关文章

  1. Atitit.web三大编程模型 Web Page Web Forms 和 MVC

    Atitit.web三大编程模型 Web Page    Web Forms 和 MVC 1. 编程模型是 Web Forms 和 MVC (Model, View, Controller). 2.  ...

  2. Atitit.web三编程模型 Web Page Web Forms 和 MVC

    Atitit.web三编程模型 Web Page    Web Forms 和 MVC 1. 编程模型是 Web Forms 和 MVC (Model, View, Controller). 2. W ...

  3. [重点翻译] ASP.NET 4.6的更新 -- 本文只摘录 Web Forms的部分

    原文出处:[重点翻译] ASP.NET 4.6的更新 -- 本文只摘录 Web Forms的部分 http://www.dotblogs.com.tw/mis2000lab/archive/2015/ ...

  4. Asp.Net复习篇之Asp.Net生命周期与Asp.Net页的生命周期

    Asp.Net生命周期与Asp.Net页的生命周期是一个比较重要的话题,有时可能似乎知道一些,但又说不出个所以然,而且时常把这两个概念混淆.现在也是该好好理清思路,把这两个概念搞懂. Asp.Net生 ...

  5. ASP.NET Web Forms 4.5的新特性

    作者:Parry出处:http://www.cnblogs.com/parry/ 一.强类型数据控件 在出现强类型数据控件前,我们绑定数据控件时,前台一般使用Eval或者DataBinder.Eval ...

  6. 运用模型绑定和web窗体显示和检索数据(Retrieving and displaying data with model binding and web forms)

    原文 http://www.asp.net/web-forms/overview/presenting-and-managing-data/model-binding/retrieving-data ...

  7. Asp.Net Web Forms/MVC/Console App中使用Autofac

    本来简单介绍了Autofac在Asp.Net Web Forms中的应用,后来又添加了mvc.控制台应用程序中使用Autofac,详情请看源码. ASP.NET Web Forms使用Autofac, ...

  8. asp.net应用程序生命周期和asp.net网页的生命周期

    一.asp.net应用程序生命周期 asp.net应用程序生命周期以浏览器向web服务器(比如IIS服务器)发送请求为起点,先后经历web服务器下的ISAPI(Internet Server Appl ...

  9. [转]Bootstrap 3.0.0 with ASP.NET Web Forms – Step by Step – Without NuGet Package

    本文转自:http://www.mytecbits.com/microsoft/dot-net/bootstrap-3-0-0-with-asp-net-web-forms In my earlier ...

随机推荐

  1. 【Java集合源代码剖析】LinkedList源代码剖析

    转载请注明出处:http://blog.csdn.net/ns_code/article/details/35787253 您好.我正在參加CSDN博文大赛.假设您喜欢我的文章,希望您能帮我投一票,谢 ...

  2. Qt容器类的对象模型及应用(线性结构篇:对于QList来说,sharable默认是false的,但对于接下来讲的QVector来说,sharable默认是true)

    用Qt做过项目开发的人,肯定使用过诸如QList.QVector.QLinkList这样的模板容器类,它们虽然名字长的不同,但使用方法都大致相同, 因为其使用方法都大体相同,很多人可能随便拿一个容器类 ...

  3. USACO 2.1 Healthy Holsteins

    Healthy HolsteinsBurch & Kolstad Farmer John prides himself on having the healthiest dairy cows ...

  4. APNs推送

    消息推送是可以指定声音的.譬如你可以对正面的反馈使用欢快的声音,对负面的反馈使用低沉一点的声音,都可以达到别出心裁让人眼前一亮的目的.你需要先放一些aiff.wav或者caf音频文件到app的资源文件 ...

  5. Elasticsearch部署异常Permission denied

    异常描述 在Linux上部署ElasticSearch时抛出了一个异常如下: log4j:ERROR setFile(null,true) call failed. java.io.FileNotFo ...

  6. caffe mnist实例 --lenet_train_test.prototxt 网络配置详解

    1.mnist实例 ##1.数据下载 获得mnist的数据包,在caffe根目录下执行./data/mnist/get_mnist.sh脚本. get_mnist.sh脚本先下载样本库并进行解压缩,得 ...

  7. mysql 导入数据库 命令操作

    window下 1.导出整个数据库 mysqldump -u 用户名 -p 数据库名 > 导出的文件名 mysqldump -u dbuser -p dbname > dbname.sql ...

  8. X Macro

    30年前我念大学时从一个朋友那里学来的一个技巧. 它是汇编语言的一个宏,但很容易转换为C语言宏. 我一直在使用它,但有意思的是我还从没在别人的代码中看到过.现在该我把这个小技巧传递下去了. 让我们举个 ...

  9. ​libz.so.1: cannot open shared object file: No such file or directory

    在虚拟机安装xtrabackup工具时候出现的报错:​​libz.so.1: cannot open shared object file: No such file or directory [ro ...

  10. submile 安装,汉化,插件

    /*删除以前配置文件*/ 删除以前版本sublime后,在删除以前版本的配置信息:直接在C盘 查询里面输入 Roming  然后查找里面的 sublime 文件夹,把他给删除掉 ----------- ...