protected void ButtonDelete_Click(object sender, EventArgs e)
        {
            if (TextBoxName.Text.Length == 0)
            {
                ScriptManager.RegisterClientScriptBlock(this, this.GetType(),
                                                        "alertMessage",
                                                        "alert('Please enter the name of the Task to be deleted.');", true);
            }

            else
            {
                using (SqlConnection conn = new SqlConnection(g_sqlConn))
                {
                    Connect(conn);


                    using (SqlCommand cmd2 = new SqlCommand(String.Format("SELECT TaskID FROM tblTasks WHERE Name='{0}' AND UserID={1} AND ProjectID={2}",
                                                                          TextBoxName.Text, Session["_CurrentUserID"], Session["_CurrentProjID"]), conn))
                    {
                        SqlDataReader sdr = cmd2.ExecuteReader();

                        while (sdr.Read())
                        {
                            Session["_CurrentTaskID"] = sdr[0].ToString();
                        }
                        sdr.Close();
                    }


                    using (SqlCommand cmd3 = new SqlCommand(String.Format("UPDATE tblIssues SET AssociatedTask = NULL WHERE AssociatedTask={0}", Session["_CurrentTaskID"]), conn))
                    {
                        try
                        {
                            cmd3.ExecuteNonQuery();
                        }

                        catch (Exception ex)
                        {
                            Response.Write(String.Format("Error while executing query...{0}", ex.ToString()));
                        }
                    }


                    using (SqlCommand cmd = new SqlCommand(String.Format("delete from tblTasks where UserID={0} and ProjectID={1} AND Name='{2}'",
                                                                         Session["_CurrentUserID"], Session["_CurrentProjID"], TextBoxName.Text), conn))
                    {
                        try
                        {
                            cmd.ExecuteNonQuery();
                        }

                        catch (Exception ex)
                        {
                            Response.Write(String.Format("Error while executing query...{0}", ex.ToString()));
                        }

                        finally
                        {
                            Disconnect(conn);
                        }
                    }
                }
            }

            this.DropDownListTaskSelect.Items.Clear();
            DropDownListTaskSelect.DataBind();
            GridViewTaskList.DataBind();
            GridViewAssociatedIssues.DataBind();
        }
        protected void ButtonNew_Click(object sender, EventArgs e)
        {
            if (TextBoxName.Text.Length == 0 || TextBoxDescription.Text.Length == 0)
            {
                ScriptManager.RegisterClientScriptBlock(this, this.GetType(),
                                                        "alertMessage",
                                                        "alert('Please enter a name and description for the Task.');", true);
            }

            else if (TextBoxExpectedStartDate.Text.Length == 0 || TextBoxExpectedDueDate.Text.Length == 0)
            {
                ScriptManager.RegisterClientScriptBlock(this, this.GetType(),
                                                        "alertMessage",
                                                        "alert('Please enter an Expected Start Date and Expected Due Date for the Task.');", true);
            }

            else if (TextBoxExpectedEffort.Text.Length == 0)
            {
                ScriptManager.RegisterClientScriptBlock(this, this.GetType(),
                                                        "alertMessage",
                                                        "alert('Please enter an Expected Effort for the Task.');", true);
            }

            else if (TextBoxExpectedDuration.Text.Length == 0)
            {
                ScriptManager.RegisterClientScriptBlock(this, this.GetType(),
                                                        "alertMessage",
                                                        "alert('Please enter an Expected Duration for the Task.');", true);
            }

            else
            {
                using (SqlConnection conn = new SqlConnection(g_sqlConn))
                {
                    Connect(conn);

                    using (SqlCommand cmd = new SqlCommand("insert into tblTasks(UserID,ProjectID,Name,Description,TaskType,ExpectedStartDate,ExpectedEndDate,ExpectedEffort,ExpectedDuration)" +
                                                           " values(@UserID, @ProjectID, @Name, @Description,@TaskType , @ExpStart, @ExpEnd, @ExpEffort, @ExpDuration)", conn))
                    {
                        try
                        {
                            cmd.Parameters.AddWithValue("@UserID", Session["_CurrentUserID"]);
                            cmd.Parameters.AddWithValue("@ProjectID", Session["_CurrentProjID"]);
                            cmd.Parameters.AddWithValue("@Name", TextBoxName.Text);
                            cmd.Parameters.AddWithValue("@Description", TextBoxDescription.Text);
                            cmd.Parameters.AddWithValue("@TaskType", g_TaskType);
                            cmd.Parameters.AddWithValue("@ExpStart", TextBoxExpectedStartDate.Text);
                            cmd.Parameters.AddWithValue("@ExpEnd", TextBoxExpectedDueDate.Text);
                            cmd.Parameters.AddWithValue("@ExpEffort", TextBoxExpectedEffort.Text);
                            cmd.Parameters.AddWithValue("@ExpDuration", TextBoxExpectedDuration.Text);

                            cmd.ExecuteNonQuery();


                            using (SqlCommand cmd2 = new SqlCommand(String.Format("SELECT TaskID FROM tblTasks WHERE Name='{0}' AND UserID={1} AND ProjectID={2}",
                                                                                  TextBoxName.Text, Session["_CurrentUserID"], Session["_CurrentProjID"]), conn))
                            {
                                SqlDataReader sdr = cmd2.ExecuteReader();

                                while (sdr.Read())
                                {
                                    Session["_CurrentTaskID"] = sdr[0].ToString();
                                }

                                sdr.Close();
                            }
                        }

                        catch (Exception ex)
                        {
                            Response.Write(String.Format("Error while executing query...{0}", ex.ToString()));
                        }

                        finally
                        {
                            Disconnect(conn);
                        }

                        Connect(conn);
                        using (SqlCommand cmd2 = new SqlCommand(String.Format("SELECT TaskID FROM tblTasks WHERE Name='{0}' AND UserID={1} AND ProjectID={2}",
                                                                              TextBoxName.Text, Session["_CurrentUserID"], Session["_CurrentProjID"]), conn))
                        {
                            SqlDataReader sdr = cmd2.ExecuteReader();

                            while (sdr.Read())
                            {
                                Session["_CurrentTaskID"] = sdr[0].ToString();
                            }
                            sdr.Close();
                        }
                        Disconnect(conn);
                    }
                }

                id_GridviewScroll.Visible          = true;
                LabelActualStartDate.Visible       = true;
                ImageButtonActualStartDate.Visible = true;
                TextBoxActualStartDate.Visible     = true;

                ImageButtonClearEnd.Visible   = true;
                ImageButtonClearPred.Visible  = true;
                ImageButtonClearResc.Visible  = true;
                ImageButtonClearStart.Visible = true;
                ImageButtonClearSuc.Visible   = true;

                LabelActualEndDate.Visible       = true;
                ImageButtonActualEndDate.Visible = true;
                TextBoxActualEndDate.Visible     = true;

                LabelDays.Visible             = true;
                LabelActualDuration.Visible   = true;
                TextBoxActualDuration.Visible = true;

                LabelActualEffort.Visible   = true;
                TextBoxActualEffort.Visible = true;

                LabelEffortCompleted.Visible   = true;
                TextBoxEffortCompleted.Visible = true;

                ButtonSave.Visible   = true;
                ButtonDelete.Visible = true;
                ButtonGantt.Visible  = true;

                LabelRescource.Visible          = true;
                TextBoxResourceAssigned.Visible = true;
                ButtonSelectResource.Visible    = true;
                ButtonAddResource.Visible       = true;

                LabelSucc.Visible            = true;
                LabelSuccDep.Visible         = true;
                TextBoxSuccessorTask.Visible = true;
                TextBoxSuccDepend.Visible    = true;
                ButtonSuccessorTask.Visible  = true;

                LabelPred.Visible              = true;
                LabelPredDep.Visible           = true;
                TextBoxPredecessorTask.Visible = true;
                TextBoxPredDepend.Visible      = true;
                ButtonPredecessorTask.Visible  = true;

                LabelAssocIssue.Visible       = true;
                ButtonAssociateIssues.Visible = true;

                this.DropDownListTaskSelect.Items.Clear();
                DropDownListTaskSelect.DataBind();
                GridViewTaskList.DataBind();
            }
        }