I have a user control. webcontrol.ascx
<div runat="server" id="abc"></div>
in webcontrol.ascx.cs, i have a method to add class name
public void ABCmethod(){ abc.Attributes["class"] = "className" };
When I create it in my default.aspx declaratively, <uc:WebControl runat="server" id=wc1" />, this ABCmethod doesn't throw any exception.
But when I created it programmatically,
protected void Page_Load(object sender, EventArgs e)
{
WebControl wc1 = new WebControl();
wc1.ABCmethod();
}
this throws an error. Saying that the abc is an Object reference not set to an instance of an object.