Question

I'm learning about Web Parts and in one point the tutorial says to do the following in Page_Init:

Page.InitComplete += new EventHandler(GenerateModeList);

The tutorial proceeds to define GenerateModeList where a list of items is added to a DropDownList. This list will consist of supported Display Modes.

It seems to me that it would be simpler to define GenerateModeList method and call it from Page_InitComplete.

Why would I want to add an additional event handler?

Was it helpful?

Solution

Probably the "GenerateModeList" method needs access to the initialized controls (like the DropDownList). The controls on the page have not been initialized at the point of Page.Init.

See the documentation on the Page.InitComplete event:

At this stage of the page's life cycle, all declared controls on the page are initialized, but the page's state is not yet populated. You can access server controls, but they will not yet contain information returned from the user.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top