Here is my simple class, where i inherit from UserControl.
public class Test:System.Web.UI.UserControl
{
public void BindGrid()
{
Response.Write(IsPostBack);
}
}
Which i call from the Page_Load event
protected void Page_Load(object sender, EventArgs e)
{
new Test().BindGrid();
}
But i get a null reference exception if i try to call any of UserControl‘s inerited properies (ispostback, request etc etc)
Any ideas why this is happening?
Edit:
It seems to work if replace the ‘ispostback’ response.write() inside the OnLoad method of Test?
Properties like IsPostback depend on the Page where the user control is hosted, well, should be hosted, as your example does not add the user control to the Controls collection of the Page, which explains the crash.