I have a page that allows you to insert a new item or update an existing item. I am using a formview for it, I have custom validation in place for the insert to check that the item number isn't already stored in the database, if it is a panel appears informing the user, if it doesnt a panel appears with a success message. I am trying to do the same for the update and i am using the same code but it isn't working. Anyone any ideas?
The code for the insert is:
protected void fvItem_ItemInserting(object sender, FormViewInsertEventArgs e)
{
//record user details
e.Values["ItemInputByUserId"] = Context.User.Identity.Name;
e.Values["ItemDateInput"] = System.DateTime.Now;
UpdatePanelGVItem.Update();
}
protected void fvItem_ItemInserted(object sender, FormViewInsertedEventArgs e)
{
if (e.Exception == null)
{
UpdatePanelGVItem.Update();
GVItem.DataBind();
fvItem.ChangeMode(FormViewMode.ReadOnly);
ModalPopupExtenderInsert.Hide();
//set success panel details
pnlSuccess.Visible = true;
lblSuccess.Text = "A new item has been successfully created";
lblSuccessHeading.Text = "Item successfully created";
}
}
protected void custValtbItemNum_ServerValidate(object source, ServerValidateEventArgs args)
{
TextBox newItem = (TextBox)fvItem.FindControl("ItemNumTextBox");
//check if item already exists in system
String ItemNum = newItem.Text;
ITEM a = (ITEM)ITEMManager.ITEMGetByNum(ItemNum);
String existItem = a.ItemNum;
args.IsValid = (ItemNum != existItem);
if (args.IsValid == true)
{
pnlSuccess.Visible = true;
}
else
{
pnlFail.Visible = true;
}
}
The code for the upadte is
protected void fvItem_ItemUpdating(object sender, FormViewUpdateEventArgs e)
{
UpdatePanelGVItem.Update();
}
// when the itemCRM is updated the grid view shows this and the popup closes
protected void fvItem_ItemUpdated(object sender, FormViewUpdatedEventArgs e)
{
if (e.Exception == null)
{
UpdatePanelGVItem.Update();
GVItem.DataBind();
fvItem.ChangeMode(FormViewMode.ReadOnly);
//set success panel details
pnlSuccess.Visible = true;
lblSuccess.Text = "CRM details have been successfully updated";
lblSuccessHeading.Text = "CRM successfully updated";
}
}
protected void CustomValTBItem_ServerValidate(object source, ServerValidateEventArgs args)
{
TextBox newItem = (TextBox)fvItem.FindControl("ItemNumTextBox");
//check if item already exists in system
String ItemNum = newItem.Text;
ITEM a = (ITEM)ITEMManager.ITEMGetByNum(ItemNum);
String existItem = a.ItemNum;
args.IsValid = (ItemNum != existItem);
if (args.IsValid == true)
{
pnlSuccess.Visible = true;
}
else
{
pnlFail.Visible = true;
}
}