Speed up development with full-stack environments for every branch.

Learn More

Understanding the Page Life Cycle in ASP.NET

5908 Runs 36890 Views 5246 Copies
Saved

Saved

mirang 126

mirang
published 4 years ago

<%@ Page Language="C#" AutoEventWireup="true"%>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>Understanding the Page Life Cycle in ASP.NET</title>
    <script language="C#" runat="server">
        StringBuilder sb = new StringBuilder();
        protected void Page_PreInit(object o, EventArgs e)
        {
            Response.Write("The Page Loaded at: " + DateTime.Now.ToLongTimeString() + "<br /><br />");
            Response.Write("<div id='mainBody'><h1>Understanding the Page Life Cycle in ASP.NET.</h1><br /><br /><div class='divTitle'>Following is the sequence in which the ASP.NET Page LifeCycle is executed : </div><br /><br />");
            sb.Append("<b>Page Pre_Init</b> - Occurs at the begining of the Page Initialization <br />");
        }

        public void Page_PreLoad(object sender, EventArgs e)
        {
            sb.Append("<b>Page Pre Load </b>- Occurs before the Load Event <br />");
        }

        public void Page_InitComplete(object sender, EventArgs e)
        {
            sb.Append("<b>Page Init Complete </b>- Occurs when the Page Initialization is Complete <br />");
        }

        void Page_LoadComplete(object sender, EventArgs e)
        {

            sb.Append("<b>Page Load Complete </b>- Occurs at the end of Load Stage of the Page Life Cycle. <br />");
        }
        protected void Page_Init(object sender, EventArgs e)
        {
            sb.Append("<b>Page Init </b>- Occurs when the Server Control is Initialized. It is the first step in the ASP.NET Page Life Cycle <br />");
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            sb.Append("<b>Page Load </b>- Occurs when the Server Control is Loaded in the Page Object <br />");
        }

        void Page_PreRenderComplete(object sender, EventArgs e)
        {
            sb.Append("<b>Page Pre Render Complete </b>- Occurs before the Page Content is Rendered <br />");
        }

        void Page_PreRender(object sender, EventArgs e)
        {
            sb.Append("<b>Page Pre Render </b>- Occurs after the Server Controls is Loaded in the Page but before the Rendering</div> <br />");
            Response.Write(sb.ToString());
        }

        /// <summary>
        /// This is the event when the page is unloaded from the server memory and ready to be returned to the client,
        /// Here the response is not available, so you cannot modify the Response
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        void Page_Unload(object sender, EventArgs e)
        {
        }
    </script>
    <style type="text/css">
    .button
    {
      border-radius:4px 4px 4px 4px;
      height:30px;
      padding:5px;
      font-size:14px;
      background-color:#6ca21e;
      color:#FFFFFF
    }
    body
    {
      background-color:#32373a;
      color:#FFFFFF;
    }
    #mainBody
    {
      background-color:#FFFFFF;
      height:100%;
      color:#32373a;
    }
    .divTitle
    {
        width: 450px;
        height: 30px;
        background-color: #fdd136;
        font-size: 14px;
    }
    </style>
</head>
<body>
    <form id="form1" runat="server">
    
    </form>
</body>
</html>
Please login/signup to get access to the terminal.

Your session has timed out.

Dismiss (the page may not function properly).