title: ASP.NET: Very simple event handling not working
body: <p>I have an object <code>Order</code> with a simple event, </p>
  
  <pre><code>Public Event ErrorOccurred(ByVal msg As String)
  </code></pre>
  
  <p>that I raise in the constructor like so when an order cannot be found (along w/setting a boolean error flag:</p>
  
  <pre><code>RaiseEvent ErrorOccurred("This order does not exist in the database.")
  [Error] = True
  </code></pre>
  
  <p>I have a webform subscribed to the order's <code>ErrorOccurred</code> event:</p>
  
  <pre><code>Public WithEvents o As New Order
  </code></pre>
  
  <p>and I have an error handler method on the form:</p>
  
  <pre><code>Private Sub OnErrorOccurred(ByVal msg As String) Handles o.ErrorOccurred
      litMsg.Text = "&lt;p class=""error-confirm""&gt;" &amp; msg &amp; "&lt;/p&gt;"
  End Sub
  </code></pre>
  
  <p>When a textbox is changed, it autoposts back to the page and employs the following logic:</p>
  
  <pre><code>Private Sub txtOrderID_TextChanged(ByVal sender As Object,_
  ByVal e As System.EventArgs) Handles txtOrderID.TextChanged
    If IsNumeric(txtOrderID.Text) Then
      If o.OrderID = 0 Then o = New Order(txtOrderID.Text)
        If Not o.Error Then
           'do stuff'
        Else 
           'error, run error handling'
        End If
        ....
  </code></pre>
  
  <p>When there is an error (when the <code>Else</code> logic is run), everything performs as expected except the event does not fire. However, since the <code>Error</code> flag is set to true, it means the event MUST have fired, since that line executes AFTER the <code>RaiseEvent</code> line. </p>
  
  <p>I've tried everything I can think of, but I cannot figure out what could be wrong. I have events strewn everywhere in my project and they all work well using virtually the same structure. What could I be doing wrong here?</p>