Click here to Skip to main content
15,892,746 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi,


protected override void OnInit(EventArgs e)
{
base.OnInit(e);
}


What is the meaning of this statement.
Posted
Updated 26-Dec-10 18:20pm
v2

On the OnInit method of a child class, you are calling the OnInit of the base class.
 
Share this answer
 
Comments
RaviRanjanKr 27-Dec-10 0:32am    
Good Answer! 5+
Sergey Alexandrovich Kryukov 27-Dec-10 1:26am    
You should have noted, that functionally this code does nothing: same as not having this overridden method.
jasna ashraf wrote:
What is the meaning of this statement.

It overriding the OnInit method to set a property on the associated control and call the base method to complete the control initialization.
 
Share this answer
 
v2
Override OnInit to perform target-specific processing in the Initialize stage of the control lifecycle.
using System;
using System.Web.UI;
using System.Web.UI.Adapters;
public class CustomControlAdapter : ControlAdapter
{
    // Override the ControlAdapter default OnInit implementation.
    protected override void OnInit (EventArgs e)
    {
        // Make the control invisible.
        Control.Visible = false;
        // Call the base method, which calls OnInit of the control,
        // which raises the control Init event.
        base.OnInit(e);
    }
}
 
Share this answer
 
I suggest you to learn OOPs first with some good books.

There's many thing I could clarify you about your statement.

a) It's overridden method that just means it is overriding the base class method (Refer polymorphisom)
b) Passing object of EventArgs class with some values if passed.
c) Calling method of base class from any child class
d) Method returning nothing(void) as a return.
e) It's protected so it can only be called by object of child inherited class only.
f) OnInit is a name of method about to be called
 
Share this answer
 
It is override for you put your code.

base.OnInit(e);
is use for call the base method. In this method, server control are initializate and set up instance.

More information on Init in the MSDN[^], you can also see page life cycle[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900