// ////////////////////////////////////////////////////////////////////////
        // EVENTS
        //
        protected void Page_Load(object sender, EventArgs e)
        {
            // Register client scripts
            this.RegisterClientScripts();

            if (!IsPostBack)
            {
                // Security check
                if (!Convert.ToBoolean(Session["sgLFS_PROJECTS_VIEW"]))
                {
                    Response.Redirect("./../../error_page.aspx?error=" + "You are not authorized to view this page. Contact your system administrator.");
                }

                // Validate query string
                if (Request.QueryString["source_page"] == null)
                {
                    Response.Redirect("./../../error_page.aspx?error=" + "Invalid query string in projects2.aspx");
                }

                // Security check
                if (!Convert.ToBoolean(Session["sgLFS_PROJECTS_ADMIN"]))
                {
                    ddlProjectType.Visible = true;
                    ddlProjectTypeAdmin.Visible = false;
                    ddlProjectType.SelectedIndex = 0;

                    ddlProjectState.Visible = true;
                    ddlProjectStateAdmin.Visible = false;
                    ddlProjectState.SelectedIndex = 0;
                }
                else
                {
                    ddlProjectType.Visible = false;
                    ddlProjectTypeAdmin.Visible = true;
                    ddlProjectTypeAdmin.SelectedIndex = 0;

                    ddlProjectState.Visible = false;
                    ddlProjectStateAdmin.Visible = true;
                    ddlProjectStateAdmin.SelectedIndex = 0;
                }

                // Tag Page
                Session.Remove("projectNavigatorNewDummy");
                Session.Remove("projectNavigator");
                Session.Remove("projectsSelected");
                hdfPageIndex.Value = "0";

                // Prepare initial data
                lblError.Visible = false;
                hdfLoginId.Value = Convert.ToInt32(Session["loginID"]).ToString();
                hdfCompanyId.Value = Session["companyID"].ToString();
                Session.Remove("lastUsedProjectsDummy");

                // If coming from
                projectSelectProjectTDS = new ProjectSelectProjectTDS();
                ProjectSelectProjectLastUsedProjectsGateway projectSelectProjectLastUsedProjectsGateway = new ProjectSelectProjectLastUsedProjectsGateway(projectSelectProjectTDS);
                projectSelectProjectLastUsedProjectsGateway.LoadByLoginId(Int32.Parse(hdfLoginId.Value), Int32.Parse(hdfCompanyId.Value));

                // ... projects.aspx or projects2.aspx
                if ((Request.QueryString["source_page"] == "projects.aspx") || (Request.QueryString["source_page"] == "projects2.aspx"))
                {
                    // Restore navigator state
                    RestoreNavigatorState();

                    // Restore data
                    projectNavigatorTDS = (ProjectNavigatorTDS)Session["lfsProjectNavigatorTDS"];
                    projectNavigator = projectNavigatorTDS.LFS_PROJECT_NAVIGATOR;

                    // Store data
                    Session["projectNavigator"] = projectNavigatorTDS.LFS_PROJECT_NAVIGATOR;

                    //... for the total rows
                    if (projectNavigatorTDS.LFS_PROJECT_NAVIGATOR.Rows.Count > 0)
                    {
                        lblTotalRows.Text = "Total Rows: " + projectNavigatorTDS.LFS_PROJECT_NAVIGATOR.Rows.Count;
                        lblTotalRows.Visible = true;
                    }
                    else
                    {
                        lblTotalRows.Visible = false;
                    }
                }

                // ... project_summary.aspx, project_edit.aspx, project_sections_navigator.aspx or project_sections_navigator2.aspx
                if ((Request.QueryString["source_page"] == "project_summary.aspx") || (Request.QueryString["source_page"] == "project_edit.aspx") || (Request.QueryString["source_page"] == "project_sections_navigator.aspx") || (Request.QueryString["source_page"] == "project_sections_navigator2.aspx") || (Request.QueryString["source_page"] == "project_costing_sheets_navigator.aspx"))
                {
                    // Restore navigator state
                    RestoreNavigatorState();

                    if (Request.QueryString["update"] == "no")
                    {
                        projectNavigatorTDS = (ProjectNavigatorTDS)Session["lfsProjectNavigatorTDS"];
                        projectNavigator = projectNavigatorTDS.LFS_PROJECT_NAVIGATOR;

                        // Store data
                        Session["projectNavigator"] = projectNavigatorTDS.LFS_PROJECT_NAVIGATOR;
                    }
                    else
                    {
                        // ... Delete store data
                        Session.Contents.Remove("lfsProjectNavigatorTDS");

                        // ... Search data with updates
                        projectNavigatorTDS = SubmitSearch();

                        // ... store datasets
                        Session["lfsProjectNavigatorTDS"] = projectNavigatorTDS;
                        Session["projectNavigator"] = projectNavigatorTDS.LFS_PROJECT_NAVIGATOR;
                    }

                    //... for the total rows
                    if (projectNavigatorTDS.LFS_PROJECT_NAVIGATOR.Rows.Count > 0)
                    {
                        lblTotalRows.Text = "Total Rows: " + projectNavigatorTDS.LFS_PROJECT_NAVIGATOR.Rows.Count;
                        lblTotalRows.Visible = true;
                    }
                    else
                    {
                        lblTotalRows.Visible = false;
                    }
                }

                // ... project_delete.aspx
                if (Request.QueryString["source_page"] == "project_delete.aspx")
                {
                    // Restore navigator state
                    RestoreNavigatorState();

                    if (Request.QueryString["update"] == "no")
                    {
                        projectNavigatorTDS = (ProjectNavigatorTDS)Session["lfsProjectNavigatorTDS"];
                        projectNavigator = projectNavigatorTDS.LFS_PROJECT_NAVIGATOR;

                        // Store data
                        Session["projectNavigator"] = projectNavigatorTDS.LFS_PROJECT_NAVIGATOR;
                    }
                    else
                    {
                        // ... Delete store data
                        Session.Contents.Remove("lfsProjectNavigatorTDS");

                        // ... Search data with updates
                        projectNavigatorTDS = SubmitSearch();

                        // ... store datasets
                        Session["lfsProjectNavigatorTDS"] = projectNavigatorTDS;
                        Session["projectNavigator"] = projectNavigatorTDS.LFS_PROJECT_NAVIGATOR;
                    }

                    //... for the total rows
                    if (projectNavigatorTDS.LFS_PROJECT_NAVIGATOR.Rows.Count > 0)
                    {
                        lblTotalRows.Text = "Total Rows: " + projectNavigatorTDS.LFS_PROJECT_NAVIGATOR.Rows.Count;
                        lblTotalRows.Visible = true;
                    }
                    else
                    {
                        lblTotalRows.Visible = false;
                    }

                    // Databind
                    if (Request.QueryString["update"] != "no")
                    {
                        if (projectNavigatorTDS.LFS_PROJECT_NAVIGATOR.Rows.Count == 0)
                        {
                            string url = "./projects.aspx?source_page=projects2.aspx&" + GetNavigatorState() + "&no_results=no";
                            Response.Redirect(url);
                        }
                    }
                }

                // ... Store datasets
                Session["projectSelectProjectTDS"] = projectSelectProjectTDS;
                Session["projectLastUsedProjects"] = projectSelectProjectTDS.LastUsedProjects;
            }
            else
            {
                // Restore datasets
                projectSelectProjectTDS = (ProjectSelectProjectTDS)Session["projectSelectProjectTDS"];

                // Restore searched data (if any)
                projectNavigatorTDS = (ProjectNavigatorTDS)Session["lfsProjectNavigatorTDS"];
                projectNavigator = projectNavigatorTDS.LFS_PROJECT_NAVIGATOR;

                //... for the total rows
                if (projectNavigatorTDS.LFS_PROJECT_NAVIGATOR.Rows.Count > 0)
                {
                    lblTotalRows.Text = "Total Rows: " + projectNavigatorTDS.LFS_PROJECT_NAVIGATOR.Rows.Count;
                }
                else
                {
                    lblTotalRows.Visible = false;
                }
            }
        }
        // ////////////////////////////////////////////////////////////////////////
        // EVENTS
        //
        protected void Page_Load(object sender, EventArgs e)
        {
            this.RegisterClientScripts();

            if (!IsPostBack)
            {
                // Security check
                if (!Convert.ToBoolean(Session["sgLFS_PROJECTS_VIEW"]))
                {
                    Response.Redirect("./../../error_page.aspx?error=" + "You are not authorized to view this page. Contact your system administrator.");
                }

                // Security check
                if (!Convert.ToBoolean(Session["sgLFS_PROJECTS_ADMIN"]))
                {
                    ddlProjectType.Visible = true;
                    ddlProjectTypeAdmin.Visible = false;
                    ddlProjectType.SelectedIndex = 0;

                    ddlProjectState.Visible = true;
                    ddlProjectStateAdmin.Visible = false;
                    ddlProjectState.SelectedIndex = 0;
                }
                else
                {
                    ddlProjectType.Visible = false;
                    ddlProjectTypeAdmin.Visible = true;
                    ddlProjectTypeAdmin.SelectedIndex = 0;

                    ddlProjectState.Visible = false;
                    ddlProjectStateAdmin.Visible = true;
                    ddlProjectStateAdmin.SelectedIndex = 0;
                }

                // Validate query string
                if ((string)Request.QueryString["source_page"] == null)
                {
                    Response.Redirect("./../../error_page.aspx?error=" + "Invalid query string in projects.aspx");
                }

                // Prepare initial data
                hdfLoginId.Value = Convert.ToInt32(Session["loginID"]).ToString();
                hdfCompanyId.Value = Session["companyID"].ToString();
                Session.Remove("lastUsedProjectsDummy");
                Session.Remove("lfsProjectNavigatorTDS");
                Session.Remove("lfsLibraryTDS");
                Session.Remove("fromAttachment");

                Session["activeTabProjects"] = "0";
                Session["dialogOpenedProjects"] = "0";

                // If coming from
                projectSelectProjectTDS = new ProjectSelectProjectTDS();
                ProjectSelectProjectLastUsedProjectsGateway projectSelectProjectLastUsedProjectsGateway = new ProjectSelectProjectLastUsedProjectsGateway(projectSelectProjectTDS);
                projectSelectProjectLastUsedProjectsGateway.LoadByLoginId(Int32.Parse(hdfLoginId.Value), Int32.Parse(hdfCompanyId.Value));

                // ... Left Menu or Out
                if ((Request.QueryString["source_page"] == "lm") || (Request.QueryString["source_page"] == "out"))
                {
                    //tdNoResults.Visible = false;
                    tNoResults.Visible = false;
                    pNoResults.Visible = false;
                }

                // ... projects2.aspx
                if (Request.QueryString["source_page"] == "projects2.aspx")
                {
                    RestoreNavigatorState();
                    if ((string)Request.QueryString["no_results"] == "yes")
                    {
                        tNoResults.Visible = true;
                        pNoResults.Visible = true;
                    }
                    else
                    {
                        tNoResults.Visible = false;
                        pNoResults.Visible = false;

                        if (!Convert.ToBoolean(Session["sgLFS_PROJECTS_ADMIN"]))
                        {
                            ddlProjectType.SelectedIndex = 0;
                            ddlProjectState.SelectedIndex = 0;
                        }
                        else
                        {
                            ddlProjectTypeAdmin.SelectedIndex = 0;
                            ddlProjectStateAdmin.SelectedIndex = 0;
                        }
                    }
                }

                // ... Store datasets
                Session["projectSelectProjectTDS"] = projectSelectProjectTDS;
                Session["projectLastUsedProjects"] = projectSelectProjectTDS.LastUsedProjects;
            }
            else
            {
                // Restore datasets
                projectSelectProjectTDS = (ProjectSelectProjectTDS)Session["projectSelectProjectTDS"];
            }
        }