protected void ModifyFarmButton_Click(object sender, EventArgs e)
    {
        //Store Farm Details and Farm Contact details into the Session
        try
        {
            ServiceAccess           serviceLoader = ServiceAccess.GetInstance();
            FarmService.FarmService farmService   = serviceLoader.GetFarm();

            //Checking For Duplicate Farm Name
            if (farmService.IsFarmNameDuplicateWhileEditingFarm(
                    GetAgentId(),
                    Convert.ToInt32(FarmIdHiddenField.Value),
                    FarmNameTextBox.Text))
            {
                ErrorLiteral.Text = "Farm name already exists, Please enter a different farm name";
                return;
            }

            IList <FarmService.ContactInfo> contacts = null;
            //Checking File Type
            if (ContactListFileUpload.HasFile)
            {
                if (ContactListFileUpload.FileName.EndsWith(".csv"))
                {
                    contacts = farmService.GetFarmListFromFile(ContactListFileUpload.FileName, Irmac.MailingCycle.BLLServiceLoader.Farm.ContactFileType.Csv, ContactListFileUpload.FileBytes, LoginUserId);
                }
                else
                {
                    if (ContactListFileUpload.FileName.EndsWith(".xls"))
                    {
                        contacts = farmService.GetFarmListFromFile(ContactListFileUpload.FileName, Irmac.MailingCycle.BLLServiceLoader.Farm.ContactFileType.Excel, ContactListFileUpload.FileBytes, LoginUserId);
                    }
                    else
                    {
                        ErrorLiteral.Text = "Invalid File Uploaded. Please Check your file Extention (Must be either .csv or .xls)";
                        return;
                    }
                }
            }

            if (contacts != null)
            {
                ContactListGridView.DataSource = contacts;
                ContactListGridView.DataBind();
                Panel1.Visible      = false;
                Panel2.Visible      = true;
                Session["Contacts"] = contacts;
                if (!IsAgentRole)
                {
                    ForAgentLiteral1.Visible = true;
                    ForAgentLiteral1.Text    = ForAgentLiteral.Text;
                }
                else
                {
                    ForAgentLiteral1.Visible = false;
                }

                ErrorLiteral.Text = "";
            }
            else
            {
                FarmService.FarmInfo farm = new FarmService.FarmInfo();
                farm.FarmId      = Convert.ToInt32(FarmIdHiddenField.Value);
                farm.FarmName    = FarmNameTextBox.Text;
                farm.MailingPlan = new FarmService.MailingPlanInfo();
                farm.MailingPlan.MailingPlanId = int.Parse(MailingPlanDropDownList.SelectedValue);
                farm.LastModifyBy          = LoginUserId;
                farm.Plots                 = new FarmService.PlotInfo[1];
                farm.Plots[0]              = new FarmService.PlotInfo();
                farm.Plots[0].PlotId       = Convert.ToInt32(PlotIdHiddenField.Value);
                farm.Plots[0].PlotName     = FarmNameTextBox.Text;
                farm.Plots[0].LastModifyBy = LoginUserId;
                farm.Plots[0].Contacts     = null;
                farm.UserId                = GetAgentId();
                farmService.UpdateFarmPlot(farm);
                Response.Redirect(GetRedirectURL());
            }
        }
        catch (Exception ex)
        {
            log.Error("UNKNOWN ERROR:", ex);
            if (ex.Message.Contains("Irmac.MailingCycle.BLL.NoDataException"))
            {
                ErrorLiteral.Text = "The file does not have any data.";
            }
            else if (ex.Message.Contains("Irmac.MailingCycle.BLL.InvalidFormatException"))
            {
                ErrorLiteral.Text = "The file is in invalid format.";
            }
            else if (ex.Message.Contains("Irmac.MailingCycle.BLL.InvalidDataException"))
            {
                ErrorLiteral.Text = "Incomplete data in the uploaded file.";
            }
            else if (ex.Message.Contains("Irmac.MailingCycle.BLL.InvalidFieldDataException"))
            {
                ErrorLiteral.Text = "Incomplete data in the uploaded file.";
            }
            else if (ex.Message.Contains("Farm Name already Exist"))
            {
                ErrorLiteral.Text = "Farm Name already exists";
            }
            else if (ex.Message.Contains("You are changing Farm Name and this will change the name of Primary Plot.This name already existing in its Plot lists. Please Provide a different Farm name."))
            {
                ErrorLiteral.Text = "You are changing Farm Name and this will change the name of Primary Plot.This name already existing in its Plot lists. Please Provide a different Farm name.";
            }
            else if (ex.Message.Contains("No valid Contact records in the uploaded File."))
            {
                ErrorLiteral.Text = "No valid Contact records in the uploaded File.";
            }
            else
            {
                ErrorLiteral.Text = "Unknown Error. Please Contact Administrator.";
            }
        }
    }