title: Cant find control on a form there for need to trap for that
body: <p>I am working with sage 200 summer edition and I have an issue with a piece of code I need to be able to do a null check on the Sage.Controls.Button but even if I place it into a var it will still crash its what is called an amendable button in windows forms.</p>
  
  <p>While true most people will stright away suggest this is a null issue and how to solve it its not that quite simple casue I am dealing with sage objects I have searched for existing refersnces for the underlyingcontrol function and cannot find any documenation on the object or how to handle the null</p>
  
  <p>If I just do the following </p>
  
  <blockquote>
    <p>var control = (Sage.Common.Controls.Button)Form.FindControlByName("saveButton").UnderlyingControl;</p>
  </blockquote>
  
  <p>And do an if statement around that it will still crash.  Any Ideas how to handle this.       </p>
  
  <pre><code>public override void ConfigureForm()
  {
      var sopOrderReturnLine = (Sage.Accounting.SOP.SOPOrderReturnLine) Form.BoundObjects[0];
  
      _itemDescription = sopOrderReturnLine.ItemDescription;
      if (sopOrderReturnLine.SOPOrderReturn.SpareBit1)
      {
                  var button = new Button();
                  button.Name = "extraInfoButton";
                  button.Text = "Extra Info...";
                  button.Alignment = ButtonAlignmentInContainer.Left;   
  
                  var buttonPanel = (ControlPanel) Form.FindControlByName("buttonPanel").UnderlyingControl;
                  buttonPanel.Controls.Add(button);
  
                  button.Click += new EventHandler(button_Click);
              }
              var control = (Sage.Common.Controls.Button)Form.FindControlByName("saveButton").UnderlyingControl;
              if (control !=null)
              {
                  var saveButton = (Sage.Common.Controls.Button)Form.FindControlByName("saveButton").UnderlyingControl;
                  saveButton.BeforeClick += new System.ComponentModel.CancelEventHandler(saveButton_BeforeClick);
              }
  }
  </code></pre>