Monday, June 27, 2005

Server control Page reference

Why does the following code generate a null reference exception?

 




 

public class MyServerControl : WebControl, INamingContainer
{
private TextBox textbox1;

protected override CreateChildControls()
{
if(! Page.IsPostBack)
{
//do stuff
}
}
}


The page reference is not set. I see this sort of example all the time on the web regarding server controls. Why is it that I can not get this to work?