Here's the problem....I have three components...A Page that contains a User Control and a Server-side control which is in the user control. The user control has a handful of events that the page listens to which change what the server-side control does.
The server control essentially creates a TV-Guide looking list filled with many many smaller ASP.NET controls that need to have events. All of these controls are created dynamically (server side obviously). Populating this server side control requires operations that are intensive in nature and should therefore be only done once per postback. Event1 and Event2 fire and basically will change things about the serverside controls rendering (sorting, filtering etc) so when they fire I need to call PopulateControls for sure.
Here's the problem: I cannot find the best place to put the call to PopulateControls. If i put it in the PageLoad, it fires and draws the list before any events. Then my events have to call PopulateControls themselves to respond to the event. If i put the call in PreRender, the server-side control's events do not fire because from what i read, they need to be created before or during PageLoad.
So where do i put this call so that I only have to call it once and so that it can respond to the proper events?
Here's some psuedo code
public class MyPage : System.Web.UI.Page
{
protected UserControl MyUserControl;
// Wire up event handlers
MyUserControl.Event1 += OnEvent1;
MyUserControl.Event2 += OnEvent2;
public Page_Load()
{
}
public PreRender()
{
PopulateControls();
}
private PopulateControls()
{
// Do intensive operation to populate controls
}
protected OnEvent1()
{
}
protected OnEvent2()
{
}
}