• asp.net C#母版页和内容页事件排版加载顺序生命周期


    asp.net C#母版页和内容页事件排版加载顺序生命周期

    关于ASP页面Page_Load发生在事件之前而导致的问题已经喜闻乐见,对于问题的解释也很全面,但是如何解决问题则较少有人说明,我就再

    简单说明一下解决方案。以下是内容页和母版页(如果有)的事件发生顺序:
    ContentPage.PreInit
    Master.Init
    ContentPage.Init
    ContentPage.InitComplite
    ContentPage.PreLoad
    ContentPage.Load
    Master.Load
    ContentPage.LoadComplete
    ContentPage.PreRender
    Master.PreRender
    ContentPage.PreRenderComplete

    就算知道了发生顺序对新手来说也不能怎么样,那么下面重点就来了:
    我们都会发现页面后台有个protected void Page_Load(object sender, EventArgs e)方法
    通常大家会把页面载入时需要做的处理代码写在里面,但是这个方法发生在click事件之前,就导致了很多小问题
    那么有没有方法是发生在事件之后呢?答案是肯定的:
    protected void Page_LoadComplete(object sender, EventArgs e)
    是不是很简单?但是这个方法仍然发生在母版加载之前,如果弹出对话框会导致母版排版混乱,那么用下面这个就好了
    protected void Page_PreRenderComplete(object sender, EventArgs e)

    于是关于生命周期的问题都迎刃而解,代码理解起来也流畅多了
    以下是页面载入过程中会激活的一些方法执行顺序,需要在页面特定阶段写代码的话可以用上:
    protected void Page_Init(object sender, EventArgs e)
    protected void Page_Load(object sender, EventArgs e)
    各种用户自定义的控件click事件
    protected void Page_LoadComplete(object sender, EventArgs e)
    protected void Page_PreRender(object sender, EventArgs e)
    protected void Page_PreRenderComplete(object sender, EventArgs e)
    protected void Page_Unload(object sender, EventArgs e)
    protected void Page_Error(object sender, EventArgs e)
    protected void Page_AbortTransaction(object sender, EventArgs e)
    protected void Page_CommitTransaction(object sender, EventArgs e)
    protected void Page_DataBinding(object sender, EventArgs e)
    protected void Page_Disposed(object sender, EventArgs e)

  • 相关阅读:
    HashMap中红黑树插入节点的调整过程
    grep使用小tips
    数字电路设计流程之LINT,CDC
    芯片设计中的efuse
    NetSuite's next generation transaction Inbound Shipment
    hadoop集群搭建
    hive安装
    慢查询SQL排查
    sipresponse
    【项目】项目200
  • 原文地址:https://www.cnblogs.com/ranran/p/4121070.html
Copyright © 2020-2023  润新知