Fickle Bits

You're doing it wrong.

Server Control Page Reference

Why does the following code generate a null reference exception?

 




1
<br /><br />public class MyServerControl : WebControl, INamingContainer<br />{<br /> private TextBox textbox1; <br /><br /> protected override CreateChildControls()<br /> {<br /> if(! Page.IsPostBack) <br /> {<br /> <span class="comments">//do stuff</span><br /> }<br /> }<br />}


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?

Comments