locked
Difference RRS feed

  • Question

  • User-797751191 posted

    Hi

      In below code what is the difference between 2 functions

    protected override void OnInit(EventArgs e)
        {
            // Set Main Variables
            iPageSize = 10;
    
            // Grab the QueryString p Value
            if (!String.IsNullOrEmpty(Request.QueryString["p"]))
            {
                try { iPage = Convert.ToInt32(Request.QueryString["p"]); }
                catch { Response.Clear(); Response.Redirect("pagination.aspx"); }
                if (iPage < 1)
                    iPage = 1;
            }
            else
                iPage = 1;
    
            base.OnInit(e);
        }
    
        protected void Page_Load(object sender, EventArgs e)
        {
    }

    Thanks

    Wednesday, July 24, 2019 7:25 AM

Answers

  • User-719153870 posted

    Hi jsshivalik,

    About this question, i suggest you can learn about the page life cycle of webform. Please refer Life Cycle.

    In the page life cycle of webform, init event occurs before load event.

    Init event is initialization step that the server control should perform to create and set instances.

    View state information cannot be used within this event, it is not populated yet.

    A load event is used to load the relevant data into the corresponding control, and view state is available.

    For what is Oninit(EventArgs e), please refer to:Here.

    For the difference between Oninit and Pageload, Please refer to Here and Here.

    The "base.OnInit(e)" in Oninit() is to ensure the parent class executes the Page_Load first.

    Best Regard,

    Yang Shen

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, July 24, 2019 9:40 AM