views:

704

answers:

2

I have an ASP.NET user control that I'm embedding in another user control. This works fine.

I need to know the best logic/method for detecting when the control is loaded. In other words, I have some display initialization logic that needs to run when the control is initially displayed. Surely there is a pattern for this.

The typical method is to put (!IsPostBack) logic in the Page_Load method of the control. This works great until you end up with a state when the Parent page has already posted back many times. My user control gets added to the page but its display does not intialize properly.

I'm hoping to find a way that keeps this logic inside the control, versus various hacking around in the codebehind of the parent page.

A: 

There is another post here on StackOverflow that seems similar. You may want to check it out, and see if it points you in the right direction.

It may also be helpful to review the page life-cycle and events.

A: 

See the following MS article. They have an example that places several controls within a user control and initializes them.

Chris Lively