I’m fairly new to the .NET framework model of doing things so any help/suggestions would be much appreciated. Basically I want to call a user control from a master page. However, I need to pass an object (a List of objects to be more specific), to the user control. I’m generating the list of objects in the Page_Load of the master page. Here’s the line in my master page that calls the user control.
<cu:Eventlisting1 runat="server" id="eventListing1"></cu:Eventlisting1>
This user control has a parameter called CalendarItems that accepts the list of items. However, if I try to set this inside of the Page_Load method, my control executes before the Page_Load and throws an exception saying CalendarItems is null. Is there any way around this?
EDIT:
To try to help clarify. I have a drop down list on this page that determines what the list of CalendarItems is so when I populate the CalendarItems list I need to be able to read the selected value from the drop down list.
You can call a initControl-function(the code that causes the exception now) from setCalendarItems.
I would normally prefer this over abusing the page-lifecycle (use Page.Init) because that could cause other problems(viewstate etc.).
Defining an initControl function in your usercontrol and call it from the controller(Page or Masterpage)after you set the CalendarItems would probably the best, because you keep as much control as possible(better than call initControl from the property).