title: Initializing class member in UserControl
body: <p>Class is derived from Control in Asp.Net C#.</p>
  
  <p>Public class member is defined as:</p>
  
  <pre><code>    public bool isPresent = true;
  </code></pre>
  
  <p>Then in Render method check is performed :</p>
  
  <pre><code>    if (isPresent)
         doSomething;
  </code></pre>
  
  <p>On a form this field is set to false:</p>
  
  <pre><code>    &lt;c:CustomControl id="CustomControl1" isPresent="false"&gt;
  </code></pre>
  
  <p>When this code is executed locally from VS, everything is fine. Being deployed to the server, however, throws exception for the line with check for "if (isPresent)", saying that object reference is not set.</p>
  
  <p>At the same time, if this line is changed to be "if (isPresent == true)", everything is fine both locally and on the server.</p>
  
  <p>Is setting of value for class member of the Control different when run from VS and from IIS? Is it initialized in IIS before comparison operation, and not before implicit check?</p>
  
  <p>UPDATE: as has been correctly pointed, this variable is a field, not a property. There is no other class member (and no property with same name).</p>
  
  <p>UPDATE2: in addition, if check for value being not null is added, there is no exception anymore. Can it be the case that object initializer sets value of the field in case of explicit comparison operation?</p>
  
  <pre><code>    if (isPresent == null)
         return;
      if (isPresent)
         doSomething;
  </code></pre>