I am working with an autogenerated edit form and trying to get controls that have added in code behind to display on the top of the form. Here is the code that I am trying to get working.
protected void MyOnItemInserted(object sender, GridInsertedEventArgs e)
{
try
{
if (e.Exception != null)
{
e.ExceptionHandled = true;
e.KeepInInsertMode = true;
check = true;
throw new AssetManager.Helper.UniqueIndexViolationException("Error: Item already exists");
}
}
catch (AssetManager.Helper.UniqueIndexViolationException ex)
{
if (e.Item is GridEditFormItem && e.Item.IsInEditMode && check)
{
AssetManager.FormException FormException = new AssetManager.FormException();
FormException.Message = ex.Message.ToString();
GridEditFormItem _form = e.Item as GridEditFormItem;
TableCell cell = _form.EditFormCell as TableCell;
for (int i = 0; i < cell.Controls.Count; i++)
{
if (cell.Controls[i].GetType() == FormException.GetType())
{
//form exception is already there, remove it and display new message
cell.Controls.Remove(FormException);
cell.Controls.Add(FormException);
}
else
//add form exception control to table cell
cell.Controls.Add(FormException);
}
}
}
catch (Exception ex)
{
}
}
I can see the control get added to teh cell.Controls collection but the cell text does not update with the message. Am I missing something that would update the cell on the postback? I am doing this in the Inserted event. Can anyone see what I might be missing?
protected void MyOnItemInserted(object sender, GridInsertedEventArgs e)
{
try
{
if (e.Exception != null)
{
e.ExceptionHandled = true;
e.KeepInInsertMode = true;
check = true;
throw new AssetManager.Helper.UniqueIndexViolationException("Error: Item already exists");
}
}
catch (AssetManager.Helper.UniqueIndexViolationException ex)
{
if (e.Item is GridEditFormItem && e.Item.IsInEditMode && check)
{
AssetManager.FormException FormException = new AssetManager.FormException();
FormException.Message = ex.Message.ToString();
GridEditFormItem _form = e.Item as GridEditFormItem;
TableCell cell = _form.EditFormCell as TableCell;
for (int i = 0; i < cell.Controls.Count; i++)
{
if (cell.Controls[i].GetType() == FormException.GetType())
{
//form exception is already there, remove it and display new message
cell.Controls.Remove(FormException);
cell.Controls.Add(FormException);
}
else
//add form exception control to table cell
cell.Controls.Add(FormException);
}
}
}
catch (Exception ex)
{
}
}