Link to home
Start Free TrialLog in
Avatar of Aravind Ranganathan
Aravind Ranganathan

asked on

label.text not displaying message on the webform

User generated imageI have 2 labels

    1) is called lblsuccessmessage
    2) is called lblerrormessage

if an update is successful then i am displaying a success message if not displaying an error message. for some reason the label is not getting displayed even when i debug through the code, it runs over it but nothing is displayed on the screen.

More Code

Code behind

namespace masterpage
{
    public partial class Inp_OEE_Sanitation : System.Web.UI.Page
    {
        

        private static Logger PageLogger = LogManager.GetCurrentClassLogger();

        const string WhichMenuItem = "Sanitation";
        const int HiddenGeneralIDField = 6;
        const int HiddenVStatusField = 7;
        const int HiddenInitialVStatusField = 8;
        string con = ConfigurationManager.ConnectionStrings["OEEDBConnectionString"].ToString();
        string PlantVal = ConfigurationManager.AppSettings["plantvalue"];

        protected void Page_Load(object sender, EventArgs e)
        {
            
           lblSuccessMessage.Text = "Entering Page Load";
            
            Calendarextender3.EndDate = DateTime.Now;

            if (todaydate.Text.Trim().Length == 0)
            {
                todaydate.Text = DateTime.Today.ToString("MM/dd/yyyy");
            }
            if (!IsPostBack)
            {
                HiddenSetDate.Text = todaydate.Text;
                PopulateGridview();
            }
            SetScreenName();

        }
        public void SetScreenName()
        {
            //lblSuccessMessage.Text = "getting SetScreenName";
            string currentPage = Path.GetFileName(Request.Url.AbsolutePath);
            //ScreenDescription [menu_name]
            //[menu_url]

            //

            using (SqlConnection sqlcon1 = new SqlConnection(con))
            {
                try
                {
                    sqlcon1.Open();
                    //string queryexe = "Select DISTINCT Line FROM [WC Info] Where Plant = " + "\'" + ThisPlant.ToLower() + "\'" + " and Line IS NOT NULL ORDER BY Line";
                    string queryexe = "SELECT menu_id, menu_name, menu_parent_id, menu_url, UseInLineMatrix, Ordinal, ToolTip, ScreenDescription FROM dbo.menuMaster WITH (nolock) WHERE  ((menu_url = @menu_urlOne) OR (menu_url = @menu_urlTwo))";
                    SqlCommand com1 = new SqlCommand(queryexe, sqlcon1);

                    com1.Parameters.Add("@menu_urlOne", SqlDbType.VarChar, 50).Value = currentPage;
                    com1.Parameters.Add("@menu_urlTwo", SqlDbType.VarChar, 50).Value = "~/" + currentPage;

                    SqlDataReader dr = com1.ExecuteReader();
                    if (dr.HasRows)
                    {
                        //LblScreenDescription/
                        while (dr.Read())
                        {
                            if (dr["ScreenDescription"].ToString().Trim().Length > 0)
                            {
                                LblScreenDescription.Text = dr["ScreenDescription"].ToString().Trim();
                                break;
                            }
                        }
                    }
                    dr.Close();


                }
                catch (Exception ex)
                {
                    PageLogger.Debug("DEBUG|" + ex.Message);
                    PageLogger.Error("ERROR|" + ex.StackTrace);

                    Console.Out.WriteLine(ex.Message);
                }
            }

        }

        public bool HardDateStop()
        {
           // lblSuccessMessage.Text = "HardDateStop";
            bool retval = false;
            if (IsPostBack)
            {
                //TodayDate 
                //No FUture date
                //Up to seven days in the past
                DateTime date1 = DateTime.Today;
                DateTime date2 = DateTime.Parse(todaydate.Text);
                if (date2 > date1)
                {
                    retval = true;
                }
                else
                {
                    retval = false;
                }
            }
            else
            {
                retval = false;
            }
            return retval;
        }

        protected void LineValues_SelectedIndexChanged(object sender, EventArgs e)
        {
            try
            {
                LoadMachineValues(LineValues.Text, PlantVal);
                
            }
            catch (Exception ex)
            {
                PageLogger.Debug("DEBUG|" + ex.Message);
                PageLogger.Error("ERROR|" + ex.StackTrace);
                lblPopUpError.Text = ex.Message;
                MPE_ERRORMESSAGES.Show();
            }
        }

        protected void LoadMachineValues(string ThisLine, string thissetting = "NOTHINGEVER")
        {
            MachineValues.Items.Clear();
            var items = new string[60];
            bool listmatchfound = false;

            string con = ConfigurationManager.ConnectionStrings["OEEDBConnectionString"].ToString();
            using (SqlConnection sqlcon = new SqlConnection(con))
            {
                try
                {
                    sqlcon.Open();
                    SqlDataReader dr;
                    string query = "SELECT Machine FROM dbo.[WC Info] WHERE (Plant = @Plant) AND (Line = @Line) GROUP BY Machine;";
                    SqlCommand com = new SqlCommand(query, sqlcon);
                    com.Parameters.Add("@Plant", SqlDbType.NVarChar, 50).Value = PlantVal;
                    com.Parameters.Add("@Line", SqlDbType.NVarChar, 50).Value = ThisLine;
                    ListItem dnfi = new ListItem();
                    dnfi.Value = "";
                    dnfi.Text = "";
                    MachineValues.Items.Add(dnfi);
                    dr = com.ExecuteReader();
                    if (dr.HasRows)
                    {
                        while (dr.Read())
                        {
                            ListItem nli = new ListItem();
                            nli.Text = dr["Machine"].ToString();
                            nli.Value = dr["Machine"].ToString();
                            if (thissetting != "NOTHINGEVER")
                            {
                                if (dr["Machine"].ToString() == thissetting)
                                {
                                    nli.Selected = true;
                                    listmatchfound = true;
                                }
                            }
                            MachineValues.Items.Add(nli);
                        }
                        if (listmatchfound == false)
                        {
                            MachineValues.SelectedIndex = 0;
                        }
                    }
                }
                catch (Exception ex)
                {
                    PageLogger.Debug("DEBUG|" + ex.Message);
                    PageLogger.Error("ERROR|" + ex.StackTrace);
                }

            }
        }


        //protected void LineValues_SelectedIndexChangedEdit(object sender, EventArgs e)
        //{
        //    //try
        //    //{
        //    //    LoadMachineValues(LineValues.Text, PlantValue.Text);
        //    //    string popup = fillFieldsBasedONProductCode();
        //    //    if (popup.Length > 0)
        //    //    {
        //    //        NEW_txtproductcode.Focus();
        //    //        lblPopUpError.Text = popup;
        //    //        MPE_ERRORMESSAGES.Show();
        //    //    }
        //    //    else
        //    //    {
        //    //        MachineValues.Focus();
        //    //    }
        //    //}
        //    //catch (Exception ex)
        //    //{
        //    //    PageLogger.Debug("DEBUG|" + ex.Message);
        //    //    PageLogger.Error("ERROR|" + ex.StackTrace);
        //    //    lblPopUpError.Text = ex.Message;
        //    //    MPE_ERRORMESSAGES.Show();
        //    //}
        //}
        

        protected void CustomValidator1_ServerValidate(object sender, ServerValidateEventArgs e)
        {
            if (Page.IsValid)
            {
                DateTime NullDateOut = Convert.ToDateTime( "1/1/0001 12:00:00 AM");
                DateTime date2;
                DateTime date1 = DateTime.Today;
                DateTime.TryParseExact(e.Value, "MM/dd/yyyy", CultureInfo.InvariantCulture, DateTimeStyles.None, out date2);

                //{1/1/0001 12:00:00 AM}

                if (date2 == NullDateOut)
                {
                    e.IsValid = false;
                    //CDateValidator.ErrorMessage = "<br />Date was in incorrect format";
                    PopulateEmptyGridView();
                }
                else
                {
                    if (date2 > date1)
                    {
                        e.IsValid = false;
                        //CDateValidator.ErrorMessage = "<br />Future Dates are not allowed.";
                        PopulateEmptyGridView();
                    }
                    else
                    {
                        e.IsValid = true;
                    }
                }
                

               
            }

        }



        protected bool FindDuplicateEntryINGridView(string Line, string Machine)
        {
           // lblSuccessMessage.Text = "Finding Duplicate Entry IN GridView";
            bool retval = false;

            try
            {
                foreach (GridViewRow row in GridView1.Rows)
                {
                    string ThisLine = ((Label)row.Cells[1].FindControl("lblItemLine")).Text;
                    string ThisMachine = ((Label)row.Cells[2].FindControl("lblItemMachine")).Text;
                    string ThisTimeStart = ((TextBox)row.Cells[3].FindControl("txtStartTime_MassEdit")).Text;
                    string ThisTimeStop = ((TextBox)row.Cells[4].FindControl("txtStopTime_MassEdit")).Text;
                    if (ThisLine.ToUpper().Trim() == Line.ToUpper().Trim())
                    {
                        if (ThisMachine.ToUpper().Trim() == Machine.ToUpper().Trim())
                        {
                            if (ThisTimeStart.ToUpper().Trim() == NEW_txtStartTime.Text)
                            {
                                if (ThisTimeStop.ToUpper().Trim() == NEW_txtStopTime.Text)
                                {
                                    ((TextBox)row.Cells[3].FindControl("txtStartTime_MassEdit")).Focus();
                                    retval = true;
                                    //GridView1.EditIndex = row.RowIndex;
                                    //btn_Create.Enabled = false;
                                    break;
                                }
                            }
                        }
                    }
                }

            }
            catch (Exception ex)
            {
                PageLogger.Debug("DEBUG|" + ex.Message);
                PageLogger.Error("ERROR|" + ex.StackTrace);
                lblErrorMessage.Text = ex.Message.ToString();
            }
            //if (retval == true)
            //{
            //    PopulateGridview();
            //}
            return retval;
        }

        protected bool FindAdditionSetEditIfFound(string Line, string Machine)
        {
            //lblSuccessMessage.Text = "FindAdditionSetEditIfFound";
            bool retval = false;
            
            try
            {
                foreach (GridViewRow row in GridView1.Rows)
                {
                    string ThisLine = ((Label)row.Cells[1].FindControl("lblItemLine")).Text;
                    string ThisMachine = ((Label)row.Cells[2].FindControl("lblItemMachine")).Text;
                    string ThisTimeStart = ((TextBox)row.Cells[3].FindControl("txtStartTime_MassEdit")).Text;
                    string ThisTimeStop = ((TextBox)row.Cells[4].FindControl("txtStopTime_MassEdit")).Text;
                    if (ThisLine.ToUpper().Trim() == Line.ToUpper().Trim())
                    {
                        if (ThisMachine.ToUpper().Trim() == Machine.ToUpper().Trim())
                        {
                            if (ThisTimeStart.ToUpper().Trim() == "12:00 AM")
                            {
                                if (ThisTimeStop.ToUpper().Trim() == "12:00 AM")
                                {

                                    ((TextBox)row.Cells[3].FindControl("txtStartTime_MassEdit")).Text = NEW_txtStartTime.Text;
                                    ((TextBox)row.Cells[3].FindControl("txtStopTime_MassEdit")).Text = NEW_txtStopTime.Text;                                    
                                    ((TextBox)row.Cells[3].FindControl("txtStartTime_MassEdit")).Focus();
                                    retval = true;
                                    //GridView1.EditIndex = row.RowIndex;
                                    //btn_Create.Enabled = false;
                                    break;
                                }
                            }
                        }
                    }
                }
                
            }
            catch (Exception ex)
            {
                PageLogger.Debug("DEBUG|" + ex.Message);
                PageLogger.Error("ERROR|" + ex.StackTrace);
                lblErrorMessage.Text = ex.Message.ToString();
            }
            //if (retval == true)
            //{
            //   // PopulateGridview();
            //}
            return retval;
        }
        
        protected void btn_Create_Click(object sender, EventArgs e)
        {
          //  lblSuccessMessage.Text = "create button was clicked";
            //ValidateAndEnterData(false);
            //todaydate

            //HiddenSetDate
            try
            {
                if (!HardDateStop())
                {
                    if (!FindAdditionSetEditIfFound(LineValues.SelectedValue.ToString(), MachineValues.SelectedValue.ToString()))
                    {
                        if (!FindDuplicateEntryINGridView(LineValues.SelectedValue.ToString(), MachineValues.SelectedValue.ToString()))
                        {
                            if (LineValues.SelectedValue.ToString().Trim().Length > 0)
                            {
                                if (SaveMassChanges())
                                {
                                    HiddenSetDate.Text = todaydate.Text;
                                    using (SqlConnection sqlcon = new SqlConnection(con))
                                    {
                                        DateTime sdt = Convert.ToDateTime(HiddenSetDate.Text + ' ' + NEW_txtStartTime.Text);
                                        DateTime ssdt = Convert.ToDateTime(HiddenSetDate.Text + ' ' + NEW_txtStopTime.Text);
                                        if (sdt > ssdt)
                                        {
                                            ssdt = ssdt.AddHours(24);
                                        }
                                        TimeSpan span = ssdt.Subtract(sdt);
                                        int TimeUsedSanitationCleaningValue = (int)span.TotalMinutes;
                                        string user = User.Identity.Name.Substring(User.Identity.Name.LastIndexOf(@"\") + 1); //;
                                        sqlcon.Open();
                                        //string query = "DELETE  FROM [General] WHERE GeneralID = @id";
                                        string query = "INSERT INTO GENERAL (Plant, [Date], Line, Machine, Start_Time, Stop_Time, VStatus, InitialVStatus, WhichMenuItem, DateEntered, [Time used], [Product Code], [Product Description], [Piece Code], [Piece Description], [User], [Sanitation Cleaning], approver) VALUES (@Plant, @DDate, @Line, @Machine, @StartTime, @StopTime, @VStatus, @InitialVStatus, @WhichMenuItem, @DateEntered, @Timeused, @ProductCode, @ProductDescription, @PieceCode, @PieceDescription, @User, @SanitationCleaning,  @approver)";
                                        //SELECT Plant, @DDate as [Date], Line, Machine, '1900-01-01 00:00:00' AS Start_Time, '1900-01-01 00:00:00' AS Stop_Time, 0 AS VStatus, 1 AS InitialVStatus,  
                                        //@WhichMenuItem AS WhichMenuItem, GETDATE() AS DateEntered, 0 as [Time used], 'Sanitation' as [Product Code], 'Sanitation' as [Product Description], 'Sanitation' as [Piece Code], 'Sanitation' as [Piece Description], @User as [User], 0 as [Sanitation Cleaning] FROM dbo.[WC Info] WHERE (Plant = @Plant) AND (sanautofill = 1)";
                                        SqlCommand com = new SqlCommand(query, sqlcon);
                                        com.Parameters.Add("@Plant", SqlDbType.NVarChar, 50).Value = PlantVal;
                                        com.Parameters.Add("@DDate", SqlDbType.DateTime).Value = HiddenSetDate.Text;
                                        com.Parameters.Add("@Line", SqlDbType.NVarChar, 50).Value = LineValues.SelectedValue.ToString();
                                        com.Parameters.Add("@Machine", SqlDbType.NVarChar, 50).Value = MachineValues.SelectedValue.ToString();
                                        //(@, @, @, @, @, @, @, @, @, @, @, @, @, @, @[, @User, @,  @Approver
                                        com.Parameters.Add("@StartTime", SqlDbType.DateTime).Value = sdt.ToString();
                                        com.Parameters.Add("@StopTime", SqlDbType.DateTime).Value = ssdt.ToString();
                                        com.Parameters.Add("@VStatus", SqlDbType.Int).Value = "0";
                                        com.Parameters.Add("@InitialVStatus", SqlDbType.Int).Value = "1";
                                        com.Parameters.Add("@WhichMenuItem", SqlDbType.NVarChar, 50).Value = WhichMenuItem;
                                        com.Parameters.Add("@DateEntered", SqlDbType.DateTime).Value = DateTime.Now.ToString();
                                        com.Parameters.Add("@TimeUsed", SqlDbType.Int).Value = TimeUsedSanitationCleaningValue.ToString();
                                        com.Parameters.Add("@ProductCode", SqlDbType.NVarChar, 50).Value = "Sanitation";
                                        com.Parameters.Add("@ProductDescription", SqlDbType.NVarChar, 50).Value = "Sanitation";
                                        com.Parameters.Add("@PieceCode", SqlDbType.NVarChar, 50).Value = "Sanitation";
                                        com.Parameters.Add("@PieceDescription", SqlDbType.NVarChar, 50).Value = "Sanitation";
                                        com.Parameters.Add("@User", SqlDbType.NVarChar, 50).Value = user;
                                        com.Parameters.Add("@SanitationCleaning", SqlDbType.Int).Value = TimeUsedSanitationCleaningValue.ToString();
                                        com.Parameters.Add("@approver", SqlDbType.NVarChar, 50).Value = user;
                                        com.ExecuteNonQuery(); 
                                        NEW_txtStartTime.Text = "";
                                        NEW_txtStopTime.Text = "";
                                        PopulateGridview();

                                    }
                                }
                            }
                        }
                        else
                        {
                            NEW_txtStartTime.Text = "";
                            NEW_txtStopTime.Text = "";
                        }
                    }
                    else
                    {
                        NEW_txtStartTime.Text = "";
                        NEW_txtStopTime.Text = "";
                    }
                }
                else
                {
                    HiddenSetDate.Text = "";
                }
            }
            catch (Exception ex)
            {
                PageLogger.Debug("DEBUG|" + ex.Message);
                PageLogger.Error("ERROR|" + ex.StackTrace);
                lblErrorMessage.Text = ex.Message.ToString();
            }
        }

        protected void BtnLoadLineMachinesForDate_CLick(object sender, EventArgs e)
        {
            //ValidateAndEnterData(false);

            //SELECT Plant, Line, Machine, '1900-01-01 00:00:00' AS Start_Time, '1900-01-01 00:00:00' AS Stop_Time, 0 AS VStatus, 1 AS InitialVStatus,  @WhichMenuItem AS WhichMenuItem, GETDATE() AS DateEntered FROMdbo.[WC Info] WHERE (Plant = @Plant) AND (sanautofill = 1)
            try
            {
                if (!HardDateStop())
                {
                    HiddenSetDate.Text = todaydate.Text;

                    if (GridView1.EditIndex>=0)
                    {
                        GridView1.EditIndex = -1;
                    }
                    //if (btn_Create.Enabled == false)
                    //{
                    //    btn_Create.Enabled = true;
                    //}
                    

                    PopulateGridview();
                    if (GridView1.Rows.Count <= 1)
                    {
                        if (GridView1.Rows[0].Cells[0].Text == "No Data Found ..!")
                        {
                            using (SqlConnection sqlcon = new SqlConnection(con))
                            {
                                string user = User.Identity.Name.Substring(User.Identity.Name.LastIndexOf(@"\") + 1); //;
                                sqlcon.Open();
                                //string query = "DELETE  FROM [General] WHERE GeneralID = @id";
                                string query = "INSERT INTO GENERAL (Plant, [Date], Line, Machine, Start_Time, Stop_Time, VStatus, InitialVStatus, WhichMenuItem, DateEntered, [Time used], [Product Code], [Product Description], [Piece Code], [Piece Description], [User], [Sanitation Cleaning])  SELECT Plant, @DDate as [Date], Line, Machine, '1900-01-01 00:00:00' AS Start_Time, '1900-01-01 00:00:00' AS Stop_Time, 0 AS VStatus, 1 AS InitialVStatus,  @WhichMenuItem AS WhichMenuItem, GETDATE() AS DateEntered, 0 as [Time used], 'Sanitation' as [Product Code], 'Sanitation' as [Product Description], 'Sanitation' as [Piece Code], 'Sanitation' as [Piece Description], @User as [User], 0 as [Sanitation Cleaning] FROM dbo.[WC Info] WHERE (Plant = @Plant) AND (sanautofill = 1)";
                                SqlCommand com = new SqlCommand(query, sqlcon);

                                com.Parameters.Add("@User", SqlDbType.NVarChar, 50).Value = user;
                                com.Parameters.Add("@Plant", SqlDbType.NVarChar, 50).Value = PlantVal;
                                com.Parameters.Add("@DDate", SqlDbType.DateTime).Value = HiddenSetDate.Text;
                                com.Parameters.Add("@WhichMenuItem", SqlDbType.NVarChar, 50).Value = WhichMenuItem;

                                com.ExecuteNonQuery();
                                PopulateGridview();
                            }
                        }

                    }

                }
                else
                {
                    HiddenSetDate.Text = "";
                }
                
                
            }
            catch (Exception ex)
            {
                PageLogger.Debug("DEBUG|" + ex.Message);
                PageLogger.Error("ERROR|" + ex.StackTrace);
                lblErrorMessage.Text = ex.Message.ToString();

            }
        }

        //

        protected void Gridview1_RowEditing(object sender, GridViewEditEventArgs e)
        {
            GridView1.EditIndex = e.NewEditIndex;
            PopulateGridview();
        }



        protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e)
        {
            try
            {
                using (SqlConnection sqlcon = new SqlConnection(con))
                {
                    sqlcon.Open();
                    string query = "DELETE  FROM [General] WHERE GeneralID = @id and WhichMenuItem = 'Sanitation'";
                    //string query = "UPDATE [General]  SET VStatus = 2 WHERE GeneralID = @id";
                    SqlCommand com = new SqlCommand(query, sqlcon);
                    com.Parameters.AddWithValue("@id", Convert.ToInt32(GridView1.DataKeys[e.RowIndex].Value.ToString()));
                    com.ExecuteNonQuery();
                    GridView1.EditIndex = -1;
                    lblSuccessMessage.Text = "Selected Row Deleted";
                    PopulateGridview();
                }
            }
            catch (Exception ex)
            {
                PageLogger.Debug("DEBUG|" + ex.Message);
                PageLogger.Error("ERROR|" + ex.StackTrace);
                lblErrorMessage.Text = ex.Message.ToString();

            }
        }

        protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)
        {
            //lblSuccessMessage.Text = "hi testing update";
            try
            {
                using (SqlConnection conn = new SqlConnection(con))
                {
                    conn.Open();


                    DateTime sdt = Convert.ToDateTime(HiddenSetDate.Text + ' ' + ((TextBox)GridView1.Rows[e.RowIndex].FindControl("txtStartTime")).Text);
                    DateTime ssdt = Convert.ToDateTime(HiddenSetDate.Text + ' ' + ((TextBox)GridView1.Rows[e.RowIndex].FindControl("txtStopTime")).Text);
                    if (sdt > ssdt)
                    {
                        ssdt = ssdt.AddHours(24);
                    }
                    TimeSpan span = ssdt.Subtract(sdt);
                    int TimeUsedSanitationCleaningValue = (int)span.TotalMinutes;

                    //approver = user
                    //
                    //
                    //
                    //

                    using (SqlCommand cmd = new SqlCommand("UPDATE General SET approver = @approver,[Sanitation Cleaning] = @SanCleaning, [Time used] =@TimeUsed, Start_Time=@StartTime, Stop_Time=@StopTime WHERE [GeneralID] = @id"))
                    {
                        cmd.CommandType = CommandType.Text;
                        //Start_Time=@, Stop_Time=@
                        string approver = User.Identity.Name.Substring(User.Identity.Name.LastIndexOf(@"\") + 1); //;
                        cmd.Parameters.Add("@approver", SqlDbType.NVarChar, 50).Value = approver;
                        cmd.Parameters.Add("@SanCleaning", SqlDbType.Int).Value = TimeUsedSanitationCleaningValue.ToString();
                        cmd.Parameters.Add("@TimeUsed", SqlDbType.Int).Value = TimeUsedSanitationCleaningValue.ToString();
                        cmd.Parameters.Add("@StartTime", SqlDbType.DateTime).Value = sdt.ToString();
                        cmd.Parameters.Add("@StopTime", SqlDbType.DateTime).Value = ssdt.ToString();
                        cmd.Parameters.Add("@id", SqlDbType.Int).Value = Convert.ToInt32(GridView1.DataKeys[e.RowIndex].Value.ToString());
                        

                        cmd.Connection = conn;
                        cmd.ExecuteNonQuery();
                    }
                }
                GridView1.EditIndex = -1;
                PopulateGridview();
                //success.Text = "Selected Row Updated";
                //btn_Create.Enabled = true;
            }
            catch (Exception ex)
            {
                PageLogger.Debug("DEBUG|" + ex.Message);
                PageLogger.Error("ERROR|" + ex.StackTrace);

                lblErrorMessage.Text = "Update was not sucessful" + ex.Message.ToString();
            }
        }

        protected void GridView1_RowCancelingEdit(object sender, GridViewCancelEditEventArgs e)
        {
            GridView1.EditIndex = -1;
            //btn_Create.Enabled = true;
            PopulateGridview();
            GridView1.DataBind();
        }



        void PopulateEmptyGridView()
        {
            //lblSuccessMessage.Text = "populate empty gridview";
            DataTable dtbl = new DataTable();
            DataTable dtb2 = new DataTable();
            using (SqlConnection sqlcon = new SqlConnection(con))
            {
                try
                {
                    sqlcon.Open();
                    var yesterday = DateTime.Today.AddDays(-1);
                    SqlCommand mcmd = new SqlCommand();
                    mcmd.Connection = sqlcon;
                    mcmd.CommandType = CommandType.Text;
                    //string amiadmin = Session["ISADMIN"].ToString() ?? "NO"; 
                    string GridQuery = "SELECT TOP (100) PERCENT Date, Line, Machine, Start_Time, Stop_Time, Plant, GeneralID, VStatus, InitialVStatus, WhichMenuItem, DateEntered FROM dbo.General WHERE (Plant = @Plant) AND (WhichMenuItem = @WhichMenuItem) AND ([Date] = @DDate) ORDER BY Line, Machine, Start_Time";
                    mcmd.Parameters.Clear();
                    mcmd.Parameters.Add("@Plant", SqlDbType.NVarChar, 50).Value = PlantVal;
                    mcmd.Parameters.Add("@DDate", SqlDbType.DateTime).Value = "12/31/9876";
                    mcmd.Parameters.Add("@WhichMenuItem", SqlDbType.NVarChar, 50).Value = WhichMenuItem;
                    mcmd.CommandText = GridQuery;
                    //mcmd.Parameters.Add("@Plant", SqlDbType.NVarChar, 50).Value = PlantValue.Text;
                    //mcmd.Parameters.Add("@DDate", SqlDbType.DateTime).Value = yesterday.ToString("yyyy/MM/dd");
                    //mcmd.Parameters.Add("@WhichMenuItem", SqlDbType.NVarChar, 50).Value = WhichMenuItem;

                    SqlDataAdapter sqlDa = new SqlDataAdapter(mcmd);

                    sqlDa.Fill(dtbl);
                    if (dtbl.Rows.Count > 0)
                    {
                        GridView1.DataSource = dtbl;
                        GridView1.DataBind();
                    }
                    else
                    {
                        dtbl.Rows.Add(dtbl.NewRow());
                        GridView1.DataSource = dtbl;
                        GridView1.DataBind();
                        GridView1.Rows[0].Cells.Clear();
                        GridView1.Rows[0].Cells.Add(new TableCell());
                        GridView1.Rows[0].Cells[0].ColumnSpan = 0;
                        GridView1.Rows[0].Cells[0].Text = "No Data Found ..!";
                        GridView1.Rows[0].Cells[0].HorizontalAlign = HorizontalAlign.Center;
                    }
                    //sqlcon.Close();

                }
                catch (Exception ex)
                {
                    PageLogger.Debug("DEBUG|" + ex.Message);
                    PageLogger.Error("ERROR|" + ex.StackTrace);
                }



            }
        }
        void PopulateGridview(bool FilterOn = false)
        {
            //lblSuccessMessage.Text = "populate gridview";
            DataTable dtbl = new DataTable();
            DataTable dtb2 = new DataTable();
            using (SqlConnection sqlcon = new SqlConnection(con))
            {
                try
                {
                    sqlcon.Open();
                    var yesterday = DateTime.Today.AddDays(-1);
                    SqlCommand mcmd = new SqlCommand();
                    mcmd.Connection = sqlcon;
                    mcmd.CommandType = CommandType.Text;
                    //string amiadmin = Session["ISADMIN"].ToString() ?? "NO"; 
                    string GridQuery = "SELECT TOP (100) PERCENT Date, Line, Machine, Start_Time, Stop_Time, Plant, GeneralID, VStatus, InitialVStatus, WhichMenuItem, DateEntered FROM dbo.General WHERE (Plant = @Plant) AND (WhichMenuItem = @WhichMenuItem) AND ([Date] = @DDate) ORDER BY Line, Machine, Start_Time";                   
                    mcmd.Parameters.Clear();
                    mcmd.Parameters.Add("@Plant", SqlDbType.NVarChar, 50).Value = PlantVal;
                    mcmd.Parameters.Add("@DDate", SqlDbType.DateTime).Value = HiddenSetDate.Text;
                    mcmd.Parameters.Add("@WhichMenuItem", SqlDbType.NVarChar, 50).Value = WhichMenuItem;
                    mcmd.CommandText = GridQuery;
                    //mcmd.Parameters.Add("@Plant", SqlDbType.NVarChar, 50).Value = PlantValue.Text;
                    //mcmd.Parameters.Add("@DDate", SqlDbType.DateTime).Value = yesterday.ToString("yyyy/MM/dd");
                    //mcmd.Parameters.Add("@WhichMenuItem", SqlDbType.NVarChar, 50).Value = WhichMenuItem;

                    SqlDataAdapter sqlDa = new SqlDataAdapter(mcmd);

                    sqlDa.Fill(dtbl);
                    if (dtbl.Rows.Count > 0)
                    {
                        GridView1.DataSource = dtbl;
                        GridView1.DataBind();
                    }
                    else
                    {
                        dtbl.Rows.Add(dtbl.NewRow());
                        GridView1.DataSource = dtbl;
                        GridView1.DataBind();
                        GridView1.Rows[0].Cells.Clear();
                        GridView1.Rows[0].Cells.Add(new TableCell());
                        GridView1.Rows[0].Cells[0].ColumnSpan = 0;
                        GridView1.Rows[0].Cells[0].Text = "No Data Found ..!";
                        GridView1.Rows[0].Cells[0].HorizontalAlign = HorizontalAlign.Center;
                    }
                    //sqlcon.Close();

                }
                catch (Exception ex)
                {
                    PageLogger.Debug("DEBUG|" + ex.Message);
                    PageLogger.Error("ERROR|" + ex.StackTrace);
                }



            }
        }




        protected void BtnSaveMassChanges_Click(object sender, EventArgs e)
        {

           // lblSuccessMessage.Text = "btn save mass changes";

            if (SaveMassChanges())
            {
                GridView1.EditIndex = -1;
                PopulateGridview();
                if (IsPostBack)
                {
                 lblSuccessMessage.Text = "Updates Completed";
                }
               
            }


        }

        protected bool SaveMassChanges()
        {
            //lblSuccessMessage.Text = "entering save mass changes";
            //lblSuccessMessage.Text = "Updates Completed";
            bool retval = false;
            try
            {
                string approver = User.Identity.Name.Substring(User.Identity.Name.LastIndexOf(@"\") + 1);
                using (SqlConnection conn = new SqlConnection(con))
                {
                    conn.Open();
                    foreach (GridViewRow grvRow in GridView1.Rows)
                    {

                        string RowStartTime = (grvRow.Cells[2].FindControl("txtStartTime_MassEdit") as TextBox).Text;
                        string RowStopTime = (grvRow.Cells[3].FindControl("txtStopTime_MassEdit") as TextBox).Text;
                        string GeneralID = grvRow.Cells[HiddenGeneralIDField].Text.Trim();
                        DateTime sdt = Convert.ToDateTime(HiddenSetDate.Text + ' ' + RowStartTime);
                        DateTime ssdt = Convert.ToDateTime(HiddenSetDate.Text + ' ' + RowStopTime);
                        if (sdt > ssdt)
                        {
                            ssdt = ssdt.AddHours(24);
                        }
                        TimeSpan span = ssdt.Subtract(sdt);
                        int SanitationCleaningTime = (int)span.TotalMinutes;
                        if (sdt != ssdt)
                        {
                            using (SqlCommand cmd = new SqlCommand("UPDATE General SET VStatus = 1, approver = @approver,[Sanitation Cleaning] = @PMTimeUsed, [Time used] =@TimeUsed, Start_Time=@StartTime, Stop_Time=@StopTime WHERE [GeneralID] = @id"))
                            {
                                cmd.CommandType = CommandType.Text;
                                cmd.Parameters.Add("@approver", SqlDbType.NVarChar, 50).Value = approver;
                                cmd.Parameters.Add("@PMTimeUsed", SqlDbType.Int).Value = SanitationCleaningTime.ToString();
                                cmd.Parameters.Add("@TimeUsed", SqlDbType.Int).Value = SanitationCleaningTime.ToString();
                                cmd.Parameters.Add("@StartTime", SqlDbType.DateTime).Value = sdt.ToString();
                                cmd.Parameters.Add("@StopTime", SqlDbType.DateTime).Value = ssdt.ToString();
                                cmd.Parameters.Add("@id", SqlDbType.Int).Value = GeneralID;
                                cmd.Connection = conn;
                                cmd.ExecuteNonQuery();
                                lblSuccessMessage.Text = "Updates Completed";
                            }
                        }
                    }
                }
                retval = true;
                //lblSuccessMessage.Visible = true;
               // lblSuccessMessage.Text = "Updates Completed";
                //GridView1.EditIndex = -1;
                //PopulateGridview();
                //lblSuccessMessage.Text = "Selected Row Updated";
                //btn_Create.Enabled = true;
            }
            catch (Exception ex)
            {
                PageLogger.Debug("DEBUG|" + ex.Message);
                PageLogger.Error("ERROR|" + ex.StackTrace);

                lblErrorMessage.Text = "Update was not sucessful" + ex.Message.ToString();
            }
            return retval;

        }



       
    }
}

Open in new window



.aspx code

<%@ Page Title="" Language="C#" MasterPageFile="~/Site1.Master" AutoEventWireup="true" CodeBehind="Inp.OEE_Sanitation.aspx.cs" Inherits="masterpage.Inp_OEE_Sanitation" %>

<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="asp" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
</asp:Content>

<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
    <asp:ToolkitScriptManager runat="server"></asp:ToolkitScriptManager>

    <div id="p1" class="HeaderDataDiv">
        <asp:UpdatePanel UpdateMode="Always" runat="server">
            <ContentTemplate>
                <asp:Table ID="DataInputTable" CssClass="HeaderTablePageInput" runat="server">
                    <asp:TableHeaderRow CssClass="TableHeaderRowDescription">
                        <asp:TableCell>
                            <asp:Label ID="LblScreenDescriptionHeader" runat="server" Text="OEE Input - "></asp:Label><asp:Label ID="LblScreenDescription" runat="server" Text="Sanitation"></asp:Label>
                            <asp:TextBox ID="SetFocusOnReload" runat="server" CssClass="DataInputTableHiddenTextBox" Text="" />
                        </asp:TableCell></asp:TableHeaderRow><asp:TableRow>
                        <asp:TableCell CssClass="DataInputTableSpanSix">
                            <asp:Table runat="server" ID="TblDataEntry" CssClass="DataInputTable_TblDataEntry">
                                <asp:TableHeaderRow>
                                    <asp:TableHeaderCell CssClass="SanitationPlannedMaintenanceDateRow" ColumnSpan="4">Date</asp:TableHeaderCell>
                                </asp:TableHeaderRow>
                                <asp:TableRow>
                                    <asp:TableCell CssClass="SanitationPlannedMaintenanceDateRow" ColumnSpan="4">
                                        <table>
                                            <tr>
                                                <td>
                                                    <asp:TextBox ID="todaydate" runat="server" TextMode="Date" ToolTip="Enter The Date" ValidationGroup="DOFORMVCHECK"></asp:TextBox>
                                                    <asp:MaskedEditValidator ID="MaskedEditValidator2" runat="server" ControlExtender="MaskedEditExtender2" ControlToValidate="todaydate" Display="Dynamic" EmptyValueBlurredText="<br />Invalid Date!!! [Enter Date in mm/dd/yyyy Format]" EmptyValueMessage="Date is required" InvalidValueBlurredMessage="<br />Invalid Date!!! [Enter Date in mm/dd/yyyy Format]" InvalidValueMessage="<br />Invalid Date!!! [Enter Date in mm/dd/yyyy Format]" IsValidEmpty="False" TooltipMessage="Date Required!!!" ValidationGroup="DOFORMVCHECK" ForeColor="Red"> </asp:MaskedEditValidator>

                                                    <asp:MaskedEditExtender ID="MaskedEditExtender2" runat="server" AcceptNegative="Left" ClearMaskOnLostFocus="true" CultureName="en-US" DisplayMoney="Left" Mask="99/99/9999" MaskType="Date" MessageValidatorTip="true" OnFocusCssClass="MaskedEditFocus"
                                                        OnInvalidCssClass="MaskedEditError" TargetControlID="todaydate">
                                                    </asp:MaskedEditExtender>

                                                    <asp:CalendarExtender ID="Calendarextender3" runat="server" Format="MM/dd/yyyy" PopupButtonID="btn_cal_Duedate" TargetControlID="todaydate"></asp:CalendarExtender>
                                                </td>
                                                <td>
                                                    <asp:Button ID="BtnLoadLineMachinesForDate" OnClick="BtnLoadLineMachinesForDate_CLick" runat="server" CssClass="SanitationPlannedMaintenanceSearchButton" Text="Load Lines and Machines Data" />
                                                    <asp:TextBox ID="HiddenSetDate" runat="server" CssClass="DataInputTableHiddenTextBox" Text="" />
                                                </td>
                                            </tr>
                                        </table>




                                    </asp:TableCell>
                                </asp:TableRow>
                                <asp:TableHeaderRow>
                                    <asp:TableHeaderCell CssClass="DataInputTable_Sanitation_COL1">Line</asp:TableHeaderCell>
                                    <asp:TableHeaderCell CssClass="DataInputTable_Sanitation_COL2">Machine</asp:TableHeaderCell>
                                    <asp:TableHeaderCell CssClass="DataInputTable_Sanitation_COL3">Start</asp:TableHeaderCell>
                                    <asp:TableHeaderCell CssClass="DataInputTable_Sanitation_COL4">Stop</asp:TableHeaderCell>
                                </asp:TableHeaderRow>
                                <asp:TableRow>
                                    <asp:TableCell CssClass="DataInputTable_Sanitation_COL1">
                                        <asp:DropDownList ID="LineValues" runat="server" DataSourceID="sqlValidLinesAdd" DataTextField="Line" DataValueField="Line" OnSelectedIndexChanged="LineValues_SelectedIndexChanged" AutoPostBack="True"></asp:DropDownList>
                                        <asp:SqlDataSource ID="sqlValidLinesAdd" runat="server" ConnectionString="<%$ ConnectionStrings:OEEDBFinalConnectionString %>" SelectCommand="SELECT Line FROM dbo.[WC Info] WHERE (Plant = @Plant)  GROUP BY Line">
                                            <SelectParameters>
                                                <asp:Parameter Name="Plant" DefaultValue='<%$ AppSettings:plantvalue%>' />
                                            </SelectParameters>
                                        </asp:SqlDataSource>
                                    </asp:TableCell>
                                    <asp:TableCell CssClass="DataInputTable_Sanitation_COL2">
                                        <asp:DropDownList ID="MachineValues" AutoPostBack="True" runat="server"></asp:DropDownList>
                                    </asp:TableCell>
                                    <asp:TableCell CssClass="DataInputTable_Sanitation_COL3">
                                        <ajaxToolkit:MaskedEditExtender runat="server"
                                            AutoComplete="false"
                                            TargetControlID="NEW_txtStartTime"
                                            Mask="99:99"
                                            MessageValidatorTip="true"
                                            OnFocusCssClass="MaskedEditFocus"
                                            OnInvalidCssClass="MaskedEditError"
                                            MaskType="Time"
                                            InputDirection="LeftToRight" AcceptAMPM="true"
                                            ErrorTooltipEnabled="True" ID="MENEWStartTIme" ClearMaskOnLostFocus="false" />
                                        <ajaxToolkit:MaskedEditValidator ID="MEVStartTime" runat="server" ControlExtender="MENEWStartTIme"
                                            ControlToValidate="NEW_txtStartTime" Display="Dynamic" InvalidValueMessage="Please enter a valid time.<br/>"
                                            SetFocusOnError="true" MinimumValueMessage="Wrong input!" EnableClientScript="true" ValidationGroup="DOFORMVCHECK">
                                        </ajaxToolkit:MaskedEditValidator>
                                        <asp:TextBox ID="NEW_txtStartTime" runat="server" Width="74px" ValidationGroup="DOFORMVCHECK"></asp:TextBox>
                                    </asp:TableCell>
                                    <asp:TableCell CssClass="DataInputTable_Sanitation_COL4">
                                        <ajaxToolkit:MaskedEditExtender runat="server"
                                            AutoComplete="false"
                                            TargetControlID="NEW_txtStopTime"
                                            Mask="99:99"
                                            MessageValidatorTip="true"
                                            OnFocusCssClass="MaskedEditFocus"
                                            OnInvalidCssClass="MaskedEditError"
                                            MaskType="Time"
                                            InputDirection="LeftToRight"
                                            ErrorTooltipEnabled="True" AcceptAMPM="true" ID="MENEWStopTIme" ClearMaskOnLostFocus="False" />
                                        <ajaxToolkit:MaskedEditValidator ID="MEVtxtStopTime" runat="server" ControlExtender="MENEWStopTIme"
                                            ControlToValidate="NEW_txtStopTime" Display="Dynamic" InvalidValueMessage="Please enter a valid time.<br/>"
                                            SetFocusOnError="true" MinimumValueMessage="Wrong input!" EnableClientScript="true" ValidationGroup="DOFORMVCHECK">
                                        </ajaxToolkit:MaskedEditValidator>
                                        <asp:TextBox ID="NEW_txtStopTime" runat="server" Width="74px" ValidationGroup="DOFORMVCHECK"></asp:TextBox>
                                    </asp:TableCell>


                                </asp:TableRow>

                            </asp:Table>

                        </asp:TableCell></asp:TableRow><asp:TableRow>
                        <asp:TableCell ColumnSpan="7"></asp:TableCell></asp:TableRow><asp:TableRow CssClass="DataInputTableSpanSix">
                        <asp:TableCell CssClass="DataInputTableButtonCell">
                            <asp:Button ID="btn_Create" runat="server" OnClick="btn_Create_Click" Text="Create Sanitation Record" ValidationGroup="DOFORMVCHECK" />
                        </asp:TableCell></asp:TableRow></asp:Table><asp:Button ID="buttonHiddenTarget" runat="server" Text="btnhdntargettest" CssClass="HiddenButtonForPopUpModal" />



                <asp:Button ID="buttonHiddenTargetI" runat="server" Text="test" CssClass="HiddenButtonForPopUpModal" />
                <asp:ModalPopupExtender ID="MPE_ERRORMESSAGES" runat="server" BackgroundCssClass="modalBackground" DropShadow="False" PopupControlID="PanelErrorMessages" TargetControlID="buttonHiddenTargetI" CancelControlID="btnPopUpErrorContinue">
                </asp:ModalPopupExtender>
                <asp:Panel ID="PanelErrorMessages" runat="server">
                    <div class="PopUpDivErrorMessage">
                        <asp:Table ID="Table1" CssClass="PopUpDivTable" runat="server">
                            <asp:TableRow CssClass="PopUpDivTableDataRow">
                                <asp:TableCell>
                                    <asp:Label ID="lblPopUpError" runat="server" Text="" CssClass="PopUpDivTableDataCellData"></asp:Label>
                                </asp:TableCell></asp:TableRow><asp:TableRow>
                                <asp:TableCell>
                                &nbsp;<br />&nbsp;
                                </asp:TableCell></asp:TableRow><asp:TableRow CssClass="PopUpDivTableButtonRow">
                                <asp:TableCell>
                                    <asp:Button ID="btnPopUpErrorContinue" runat="server" Text="Continue" UseSubmitBehavior="False" /><br />
                                    &nbsp;
                                </asp:TableCell></asp:TableRow></asp:Table></div></asp:Panel><asp:GridView ID="GridView1" CssClass="GridViewMasterSettings MassInputSanPM" runat="server" CellPadding="3" AutoGenerateColumns="False" ShowHeaderWhenEmpty="True" DataKeyNames="GeneralID" ViewStateMode="Enabled" AllowPaging="false" OnRowCancelingEdit="GridView1_RowCancelingEdit" OnRowDeleting="GridView1_RowDeleting" AllowSorting="True" OnRowEditing="Gridview1_RowEditing" OnRowUpdating="GridView1_RowUpdating">
                    <FooterStyle BackColor="#fbe6b9" ForeColor="#000066" Wrap="True" />
                    <HeaderStyle CssClass="GridViewMasterSettingsth" />
                    <PagerStyle BackColor="#fbe6b9" ForeColor="#000066" HorizontalAlign="Left" />
                    <RowStyle CssClass="GridViewMasterSettingsRow" />
                    <AlternatingRowStyle CssClass="GridViewMasterSettingsRowAlternatingRow" />
                    <SelectedRowStyle BackColor="#669999" Font-Bold="True" ForeColor="White" />
                    <SortedAscendingCellStyle BackColor="#F1F1F1" />
                    <SortedAscendingHeaderStyle BackColor="#007DBB" />
                    <SortedDescendingCellStyle BackColor="#CAC9C9" />
                    <SortedDescendingHeaderStyle BackColor="#00547E" />

                    <Columns>
                        <asp:TemplateField HeaderText="Date">
                            <ControlStyle CssClass="GridViewMasterSettingsRowProductCodeItem" />
                            <HeaderStyle CssClass="GridViewMasterSettingsRowProductCodeHeader" />
                            <ItemStyle CssClass="GridViewMasterSettingsRowProductCodeItem" />
                            <HeaderTemplate>
                                <asp:Label ID="lblDate" Text="Date" runat="server" Font-Size="Medium" />
                                <br />
                            </HeaderTemplate>
                            <ItemTemplate>
                                <asp:Label ID="lblDatetext" runat="server" Text='<%# Eval("[DAte]", "{0:MM/dd/yyyy}")  %>' Width="6px"></asp:Label></ItemTemplate></asp:TemplateField><asp:TemplateField HeaderText="Line">
                            <ControlStyle CssClass="GridViewMasterSettingsRowProductCodeItem" />
                            <HeaderStyle CssClass="GridViewMasterSettingsRowProductCodeHeader" />
                            <ItemStyle CssClass="GridViewMasterSettingsRowProductCodeItem" />
                            <HeaderTemplate>
                                <asp:Label ID="LineLbl" Text="Line" runat="server" Font-Size="Medium" />
                                <br />
                            </HeaderTemplate>
                            <ItemTemplate>
                                <asp:Label ID="lblItemLine" runat="server" Text='<%# Eval("Line") %>' Width="6px"></asp:Label></ItemTemplate><EditItemTemplate>
                                <asp:Label ID="lblEDitItemLine" runat="server" Text='<%# Eval("Line") %>' Width="6px"></asp:Label></EditItemTemplate></asp:TemplateField><asp:TemplateField HeaderText="Machine">
                            <ControlStyle CssClass="GridViewMasterSettingsRowProductCodeItem" />
                            <HeaderStyle CssClass="GridViewMasterSettingsRowProductCodeHeader" />
                            <ItemStyle CssClass="GridViewMasterSettingsRowProductCodeItem" />
                            <HeaderTemplate>
                                <asp:Label ID="MachineLbl" Text="Machine" runat="server" Font-Size="Medium" />
                                <br />
                            </HeaderTemplate>
                            <ItemTemplate>
                                <asp:Label ID="lblItemMachine" runat="server" Text='<%# Eval("Machine") %>' Width="6px"></asp:Label></ItemTemplate><EditItemTemplate>
                                <asp:Label ID="lblEditItemMachine" runat="server" Text='<%# Eval("Machine") %>' Width="6px"></asp:Label></EditItemTemplate></asp:TemplateField><asp:TemplateField HeaderText="Start Time" HeaderStyle-CssClass="GridViewMasterSettingsRowStartTime" ControlStyle-CssClass="GridViewMasterSettingsRowStartTime" ItemStyle-CssClass="GridViewMasterSettingsRowStartTime">
                            <ControlStyle CssClass="GridViewMasterSettingsRowStartTime" />
                            <HeaderStyle CssClass="GridViewMasterSettingsRowStartTime" />
                            <ItemStyle CssClass="GridViewMasterSettingsRowStartTime" />
                            <HeaderTemplate>
                                <asp:Label ID="StartT" Text="Start Time" runat="server" />
                                <br />
                            </HeaderTemplate>
                            <ItemTemplate>


                                <ajaxToolkit:MaskedEditExtender runat="server"
                                    AutoComplete="false"
                                    TargetControlID="txtStartTime_MassEdit"
                                    Mask="99:99"
                                    MessageValidatorTip="true"
                                    OnFocusCssClass="MaskedEditFocus"
                                    OnInvalidCssClass="MaskedEditError"
                                    MaskType="Time"
                                    InputDirection="LeftToRight" AcceptAMPM="true"
                                    ErrorTooltipEnabled="True" ID="MASSMEEditStartTIme" ClearMaskOnLostFocus="false" />
                                <ajaxToolkit:MaskedEditValidator ID="MASSMEEVStartTime" runat="server" ControlExtender="MASSMEEditStartTIme"
                                    ControlToValidate="txtStartTime_MassEdit" Display="Dynamic" InvalidValueMessage="Please enter a valid time.<br/>"
                                    SetFocusOnError="true" MinimumValueMessage="Wrong input!" EnableClientScript="true" ValidationGroup="DOEFORMVCHECK">
                                </ajaxToolkit:MaskedEditValidator><asp:TextBox ID="txtStartTime_MassEdit" Text='<%# String.Format("{0:hh}:{0:mm} {0:tt}", Eval("Start_Time")) %>' runat="server" Height="17px" Width="92px" />

                            </ItemTemplate>
                            <EditItemTemplate>
                                <ajaxToolkit:MaskedEditExtender runat="server"
                                    AutoComplete="false"
                                    TargetControlID="txtStartTime"
                                    Mask="99:99"
                                    MessageValidatorTip="true"
                                    OnFocusCssClass="MaskedEditFocus"
                                    OnInvalidCssClass="MaskedEditError"
                                    MaskType="Time"
                                    InputDirection="LeftToRight" AcceptAMPM="true"
                                    ErrorTooltipEnabled="True" ID="MEEditStartTIme" ClearMaskOnLostFocus="false" />
                                <ajaxToolkit:MaskedEditValidator ID="MEEVStartTime" runat="server" ControlExtender="MEEditStartTIme"
                                    ControlToValidate="txtStartTime" Display="Dynamic" InvalidValueMessage="Please enter a valid time.<br/>"
                                    SetFocusOnError="true" MinimumValueMessage="Wrong input!" EnableClientScript="true" ValidationGroup="DOEFORMVCHECK">
                                </ajaxToolkit:MaskedEditValidator><asp:TextBox ID="txtStartTime" Text='<%# String.Format("{0:hh}:{0:mm} {0:tt}", Eval("Start_Time")) %>' runat="server" Height="17px" Width="92px" />
                            </EditItemTemplate>
                            <FooterTemplate>
                                <asp:TextBox ID="StartTimefooter" runat="server" />
                            </FooterTemplate>
                        </asp:TemplateField>
                        <asp:TemplateField HeaderText="Stop Time" HeaderStyle-CssClass="GridViewMasterSettingsRowStopTime" ControlStyle-CssClass="GridViewMasterSettingsRowStopTime" ItemStyle-CssClass="GridViewMasterSettingsRowStopTime">
                            <ControlStyle CssClass="GridViewMasterSettingsRowStopTime" />
                            <HeaderStyle CssClass="GridViewMasterSettingsRowStopTime" />
                            <ItemStyle CssClass="GridViewMasterSettingsRowStopTime" />
                            <HeaderTemplate>
                                <asp:Label ID="StopT" Text="Stop Time" runat="server" />
                                <br />
                            </HeaderTemplate>
                            <ItemTemplate>
                                <ajaxToolkit:MaskedEditExtender runat="server"
                                    AutoComplete="false"
                                    TargetControlID="txtStopTime_MassEdit"
                                    Mask="99:99"
                                    MessageValidatorTip="true"
                                    OnFocusCssClass="MaskedEditFocus"
                                    OnInvalidCssClass="MaskedEditError"
                                    MaskType="Time"
                                    InputDirection="LeftToRight" AcceptAMPM="true"
                                    ErrorTooltipEnabled="True" ID="MASSEDITMEEditStartTIme" ClearMaskOnLostFocus="false" />
                                <ajaxToolkit:MaskedEditValidator ID="MASSEDITMEEVStartTime" runat="server" ControlExtender="MASSEDITMEEditStartTIme"
                                    ControlToValidate="txtStopTime_MassEdit" Display="Dynamic" InvalidValueMessage="Please enter a valid time.<br/>"
                                    SetFocusOnError="true" MinimumValueMessage="Wrong input!" EnableClientScript="true" ValidationGroup="DOEFORMVCHECK">
                                </ajaxToolkit:MaskedEditValidator><asp:TextBox ID="txtStopTime_MassEdit" Text='<%# String.Format("{0:hh}:{0:mm} {0:tt}", Eval("Stop_Time")) %>' runat="server" Height="17px" Width="92px" />

                            </ItemTemplate>
                            <EditItemTemplate>
                                <ajaxToolkit:MaskedEditExtender runat="server"
                                    AutoComplete="false"
                                    TargetControlID="txtStopTime"
                                    Mask="99:99"
                                    MessageValidatorTip="true"
                                    OnFocusCssClass="MaskedEditFocus"
                                    OnInvalidCssClass="MaskedEditError"
                                    MaskType="Time"
                                    InputDirection="LeftToRight" AcceptAMPM="true"
                                    ErrorTooltipEnabled="True" ID="MEEditStopTIme" ClearMaskOnLostFocus="false" />
                                <ajaxToolkit:MaskedEditValidator ID="MEEVStopTime" runat="server" ControlExtender="MEEditStopTIme"
                                    ControlToValidate="txtStopTime" Display="Dynamic" InvalidValueMessage="Please enter a valid time.<br/>"
                                    SetFocusOnError="true" MinimumValueMessage="Wrong input!" EnableClientScript="true" ValidationGroup="DOEFORMVCHECK">
                                </ajaxToolkit:MaskedEditValidator><asp:TextBox ID="txtStopTime" Text='<%# String.Format("{0:hh}:{0:mm} {0:tt}", Eval("Stop_Time"))  %>' runat="server" Height="17px" Width="92px" />
                            </EditItemTemplate>
                            <FooterTemplate>
                                <asp:TextBox ID="StopTimefooter" runat="server" />
                            </FooterTemplate>
                        </asp:TemplateField>
                        <asp:TemplateField HeaderStyle-CssClass="GridViewMasterSettingsRowEditDeleteColumn" ControlStyle-CssClass="GridViewMasterSettingsRowEditDeleteColumn" ItemStyle-CssClass="GridViewMasterSettingsRowEditDeleteColumn">
                            <HeaderTemplate>
                            </HeaderTemplate>
                            <ItemTemplate>
                                <asp:ImageButton ImageUrl="~/Images/Delete-Button-PNG-Image.png" runat="server" ID="ITDeleteImageBUtton" TabIndex="-1" CommandName="Delete" ToolTip="Reject" Width="20px" Height=" 20px" OnClientClick="return confirm('Are you sure you want to reject this record?  There is no process to undo this action.');" />
                            </ItemTemplate>
                            <EditItemTemplate>
                                <asp:ImageButton ImageUrl="~/Images/save-icon.png" runat="server" CommandName="Update" ToolTip="Update" Width="20px" Height=" 20px" />
                                <asp:ImageButton ImageUrl="~/Images/cancel-button_318-99290.png" runat="server" CommandName="Cancel" ToolTip="Cancel" Width="20px" Height=" 20px" />
                            </EditItemTemplate>

                            <ControlStyle CssClass="GridViewSanitationPlannedMaintenanceSettingsRowEditDeleteColumn" />
                            <HeaderStyle CssClass="GridViewSanitationPlannedMaintenanceSettingsRowEditDeleteColumn" />
                            <ItemStyle CssClass="GridViewSanitationPlannedMaintenanceSettingsRowEditDeleteColumn" />

                        </asp:TemplateField>
                        <asp:BoundField DataField="GeneralID" HeaderStyle-CssClass="GridViewDontShow" FooterStyle-CssClass="GridViewDontShow" ItemStyle-CssClass="GridViewDontShow" ControlStyle-CssClass="GridViewDontShow">
                            <ControlStyle CssClass="GridViewDontShow" />
                            <FooterStyle CssClass="GridViewDontShow" />
                            <HeaderStyle CssClass="GridViewDontShow" />
                            <ItemStyle CssClass="GridViewDontShow" />
                        </asp:BoundField>
                        <asp:BoundField DataField="VStatus" HeaderStyle-CssClass="GridViewDontShow" FooterStyle-CssClass="GridViewDontShow" ItemStyle-CssClass="GridViewDontShow" ControlStyle-CssClass="GridViewDontShow">
                            <ControlStyle CssClass="GridViewDontShow" />
                            <FooterStyle CssClass="GridViewDontShow" />
                            <HeaderStyle CssClass="GridViewDontShow" />
                            <ItemStyle CssClass="GridViewDontShow" />
                        </asp:BoundField>
                        <asp:BoundField DataField="InitialVStatus" HeaderStyle-CssClass="GridViewDontShow" FooterStyle-CssClass="GridViewDontShow" ItemStyle-CssClass="GridViewDontShow" ControlStyle-CssClass="GridViewDontShow">
                            <ControlStyle CssClass="GridViewDontShow" />
                            <FooterStyle CssClass="GridViewDontShow" />
                            <HeaderStyle CssClass="GridViewDontShow" />
                            <ItemStyle CssClass="GridViewDontShow" />
                        </asp:BoundField>
                    </Columns>
                </asp:GridView>
                <table style="width: 100%">
                    <tr>
                        <td style="float: right;">
                            <asp:Button ID="BtnSaveMassChanges" runat="server" Text="Save Changes" OnClick="BtnSaveMassChanges_Click" />
                        </td>
                    </tr>
                </table>



            </ContentTemplate>
        </asp:UpdatePanel>



    </div>
    
        <asp:Label ID="lblSuccessMessage" Text="" runat="server" ForeColor="Green" />
        <br />
        <asp:Label ID="lblErrorMessage" Text="" runat="server" ForeColor="Red" />
    <br />
    </asp:Content>

Open in new window

Avatar of AndyAinscow
AndyAinscow
Flag of Switzerland image

The label is set with visible=true in the properties I hope.
Avatar of Aravind Ranganathan
Aravind Ranganathan

ASKER

@AndyAinscow i have added the properties picture above.
So it isn't that then.
@AndyAinscow nope its not
We need more code to identify the problem in this case, both front and back...
I think on your page load you might be hiding the label? or maybe you are missing to consider a Post back?
@Nikoloz Khelashvili added more code
@Chinmay Patel i looked into postback and added this check  

 if (IsPostBack)
                {
                 lblSuccessMessage.Text = "Updates Completed";
                }

it is still running thorough it and not displaying any messages.
Hi Aravind,

Just to check couple of points, can you add some text in the label and confirm that it is visible when the page loads first time.
<asp:Label ID="lblSuccessMessage" Text="TEST MESSAGE" runat="server" ForeColor="Green" />

Open in new window


Regards,
Chinmay.
@Chinmay Patel yea i have tried that already User generated imageUser generated image
these lines are commented out.
  //lblSuccessMessage.Visible = true;
               // lblSuccessMessage.Text = "Updates Completed";
                //GridView1.EditIndex = -1;
                //PopulateGridview();
                //lblSuccessMessage.Text = "Selected Row Updated";
                //btn_Create.Enabled = true;

Open in new window


perhaps uncomment out them.
Ok. In your aspx.cs search for any other occurrence of : lblSuccessMessage and if there is none than the code you have shown, please share the entire page(ASPX and CS).
@Chinmay Patel i have searched for other occurrences of  lblsuccessmessages there is one more occurrence in the delete method. i have posted the entire ASPX and CS code above.
@David Johnson i have commented them out for a reason, i am displaying the message in the    

if (SaveMassChanges())
            {
}

based on the retval.
@Chinmay Patel i have posted entire code .aspx and .cs
Have tried to put brake point on the line 727, where is written
 lblSuccessMessage.Text = "Updates Completed";

Open in new window

and check that time if element Visible property is true?
Hello,

Each and every places that you have used this label is commented. Kindly remove comment and then check again.
This question needs an answer!
Become an EE member today
7 DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform.
View membership options
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.