0

I`m working with an ASP.Net Web Forms Application.

I have an Entity Booking with a Property public virtual Reason Reason which can be set over a dropdown-control.

The exisiting code (ascx.cs-File) goes like this:

if(DropdownReasonState.Enabled)
  var booking.Reason = booking.bookingState == BookingState.Booked ? DropdownReasonState.SelectedValue() : null;

If the state is set to Booked, it works perfectly fine. If the State is something else than Booked booking.Reason is not set to null. Instead the previous reason of the entity persists, which leads to faulty behaviour.

If I do something like this, so I can debug it:

if(DropdownState.Enabled){
   if (booking.BookingState == BookingState.Booked)
       booking.Reason = DropdownReasonState.SelectedValue();
   else
       booking.Reason = null;
}

it works - but only if I debug into the else-part. Otherwise the else part is hit but Reason is never set to null.

Why is it only working if I am debugging it?

codlix
  • 858
  • 1
  • 8
  • 24
  • It sounds like you are asking why `booking.bookingState == BookingState.Booked` is always true? Perhaps it is. – Neil Aug 11 '20 at 09:59
  • No, I am asking, why `booking.Reason = null` is not `null`. I did the following. I've put a breakpoint on the line where `Reason` is set to null, the breakpoint gets hit and it works. If I remove the breakpoint, the `Reason`-Value is not set to `null` and remains in the previous state, even though the test-case is exactly the same. I've put an counter before `booking.Reason=null` and tracked if the line is actually it and verified in that way, that the else-part is hit and the value actually should be `null`. This makes absolutly no sense to me! – codlix Aug 11 '20 at 12:26
  • Is `booking.Reason` really `null` **after** the line is executed? I suspect that `null` isn't a valid value for this property and it just gets swallowed. How is the set accessor for `Reason` implemented? Print the value of `booking.Reason` before and after you changed it to your output stream and see if it changes. – keco Aug 12 '20 at 07:41
  • I`ve digged a little bit deeper and my problem is a duplicate of this `https://stackoverflow.com/a/12834578/10781626` and it is already answered. Nevertheless thanks for the response! – codlix Aug 12 '20 at 09:01

0 Answers0