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?