Posted in General

Who fires events in WebForm?

This was a reply to a post from someone on dotnetjunkies. It says “There are events like Page_Load, OnPreRender, and so on events, who fires it, exactly. Don’t say .NEt framework, it is like Universe. Be specific.” Obviously this person wants exact answers and looks like got the passion for understanding unknown.

Ok in simple terms it is Control. In .NET we have the concept of Controls. A control can have many child controls, they can have any number of child controls and so on. It is Composite Pattern (GOOGLE for it, if you are intrested). Now each control should be rendered to client, during this process we have several events.

Firstly we need to Initilize, Load, CreateChildControls and finally render. So the same controls will fire all these events for themselves. Again child controls will do the same firing.

For example if you take DataGrid, it will have many rows, which has many cells, which inturn might have controls (buttons, labels and so on). They implemented it nicely using Composite Pattern. Now intresting part is even the System.Web.UI.Page class is a Control too (it inherits from Control, if you look at the class heirarchy).

There are many other events apart from the ones mentioned above like Loading of ViewState, saving ViewState bla bla.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s