I have a problem with updating some inner contents from a dialogue. I open an object in a window, and this object has a series of different inner content fields. The customer wanted easier edit for these, so I made a custom form where he could add new values in one save, rather than adding one at a time. Anyways.. When I save this form, I do the following for each of the three inner content fields:
var distanceValues = (from ctv in repDistance.Items.Cast<RepeaterItem>()
where ctv.ItemType == ListItemType.AlternatingItem || ctv.ItemType == ListItemType.Item
select new
{
TypeId = ctv.FindControl("hidTypeId") != null ? Utils.GetIntOnly((ctv.FindControl("hidTypeId") as HiddenField).Value) : 0,
Value = ctv.FindControl("txtValue") != null ? (ctv.FindControl("txtValue") as TextBox).Text : string.Empty
}).Where(x => x.TypeId != 0);
foreach (var distanceValue in distanceValues)
{
var existingItems = _hotel.Distances.GetAll();
string val = distanceValue.Value == "0" ? string.Empty : distanceValue.Value;
DistanceType type = (DistanceType)Enum.ToObject(typeof(DistanceType), distanceValue.TypeId);
var check = existingItems.FirstOrDefault(x => x.DistanceType == type);
bool add = check == null && !string.IsNullOrEmpty(val);
bool update = check != null && !string.IsNullOrEmpty(val) && check.Value != val;
bool delete = check != null && string.IsNullOrEmpty(val);
if (add)
{
var newItem = _hotel.Distances.AddNew<Distance>();
newItem.DistanceType = type;
newItem.Value = val;
newItem.UpdateChanges();
}
else if (update)
{
check.Value = val;
check.UpdateChanges();
}
else if (delete)
{
_hotel.Distances.Delete(check.ContentId);
}
}
_hotel.UpdateChanges(false, false);
WFContext.RefreshStartupWindow();
Response.Redirect(Request.RawUrl);
Shortly explained, I iterate through a repeater (the form) and figure out what values have been added, changed and set to empty or zero (deleted).
All works well, the object is saved and the window with the object refreshes, BUT the inner content field is not refreshed. I have to close the window and open it again for the field to catch up with the changes. Why is this?