I've a user control which contains asp:Literal.
<div>
<asp:Literal id="MenuContainer" runat="server" />
</div>
There is a method in code-behind page which initializes the control:
internal void Setup(MyBusinessObject obj)
{
MenuObject menu = MenuHelper.GetMenu(obj.State);
if(obj == null)
MenuContainer.Visible = false;
//other code
}
In the page where the control is used I call Setup method of control in LoadComplete event handler (I was first calling it in Load event). Irrespective of MyBusinessObject being null or not null, when I access Literal on user-control I get error:
Object reference not set to an instance of an object.
What is the reason and what is the remedy for this?