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

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

                // Security check
                if (!(Convert.ToBoolean(Session["sgLFS_VIEWS_ADD"])))
                {
                    if ((string)Request.QueryString["work_type"] == "Rehab Assessment")
                    {
                        if (!(Convert.ToBoolean(Session["sgLFS_CWP_REHABASSESSMENT_VIEW"])))
                        {
                            Response.Redirect("./../../error_page.aspx?error=" + "You are not authorized to view this page. Contact your system administrator.");
                        }
                    }

                    if ((string)Request.QueryString["work_type"] == "Full Length Lining")
                    {
                        if (!(Convert.ToBoolean(Session["sgLFS_CWP_FULLLENGTHLINING_VIEW"])))
                        {
                            Response.Redirect("./../../error_page.aspx?error=" + "You are not authorized to view this page. Contact your system administrator.");
                        }
                    }

                    if ((string)Request.QueryString["work_type"] == "Junction Lining")
                    {
                        if (!(Convert.ToBoolean(Session["sgLFS_CWP_JUNCTIONLINING_VIEW"])))
                        {
                            Response.Redirect("./../../error_page.aspx?error=" + "You are not authorized to view this page. Contact your system administrator.");
                        }
                    }

                    if ((string)Request.QueryString["work_type"] == "Point Repairs")
                    {
                        if (!(Convert.ToBoolean(Session["sgLFS_CWP_POINTREPAIRS_VIEW"])))
                        {
                            Response.Redirect("./../../error_page.aspx?error=" + "You are not authorized to view this page. Contact your system administrator.");
                        }
                    }

                    if ((string)Request.QueryString["work_type"] == "Manhole Rehabilitation")
                    {
                        if (!(Convert.ToBoolean(Session["sgLFS_CWP_MANHOLEREHABILITATION_VIEW"])))
                        {
                            Response.Redirect("./../../error_page.aspx?error=" + "You are not authorized to view this page. Contact your system administrator.");
                        }
                    }
                }

                // Tag page
                hdfWorkType.Value = (string)Request.QueryString["work_type"];
                hdfProjectId.Value = (string)Request.QueryString["project_id"];
                hdfCompanyId.Value = Session["companyID"].ToString();
                hdfUpdate.Value = "no";

                ViewState["columnsToDisplayPageIndex"] = 0;
                ViewState["sortPageIndex"] = 0;

                Session.Remove("workTypeViewDisplay");
                Session.Remove("workTypeViewDisplayDummy");
                Session.Remove("workTypeViewSort");
                Session.Remove("workTypeViewSortDummy");
                Session.Remove("workViewDisplayTemp");
                Session.Remove("workViewSortTemp");
                Session.Remove("workViewConditionNew");
                Session.Remove("workViewConditionNewDummy");

                WorkViewGateway workViewGateway = new WorkViewGateway();
                hdfViewId.Value = (workViewGateway.GetLastViewId()+1).ToString().Trim();

                // Prepare initial data
                // ... For view type
                WorkViewTypeList workViewTypeList = new WorkViewTypeList(new DataSet());
                workViewTypeList.LoadAndAddItem("(Select a type)", Int32.Parse(hdfCompanyId.Value));
                ddlType.DataSource = workViewTypeList.Table;
                ddlType.DataValueField = "Type";
                ddlType.DataTextField = "Type";
                ddlType.DataBind();
                ddlType.SelectedIndex = 0;

                // ... Global Views check
                if (!Convert.ToBoolean(Session["sgLFS_GLOBALVIEWS_ADD"]))
                {
                    ddlType.Items.Remove("Global");
                }

                // If coming from
                // ... ra_navigator.aspx, ra_navigator2.aspx, fl_navigator.aspx, fl_navigator2.aspx, jl_navigator.aspx, jl_navigator2.aspx, pr_navigator.aspx or pr_navigator2.aspx , mr_navigator.aspx, mr_navigator2.aspx
                if ((Request.QueryString["source_page"] == "ra_navigator.aspx") || (Request.QueryString["source_page"] == "ra_navigator2.aspx") || (Request.QueryString["source_page"] == "fl_navigator.aspx") || (Request.QueryString["source_page"] == "fl_navigator2.aspx") || (Request.QueryString["source_page"] == "jl_navigator.aspx") || (Request.QueryString["source_page"] == "jl_navigator2.aspx") || (Request.QueryString["source_page"] == "pr_navigator.aspx") || (Request.QueryString["source_page"] == "pr_navigator2.aspx") || (Request.QueryString["source_page"] == "mr_navigator.aspx") || (Request.QueryString["source_page"] == "mr_navigator2.aspx"))
                {
                    // ... For Grids
                    workViewTDS = new WorkViewTDS();

                    workTypeViewDisplay = new WorkViewTDS.LFS_WORK_TYPE_VIEW_DISPLAYDataTable();
                    workTypeViewSort = new WorkViewTDS.LFS_WORK_TYPE_VIEW_SORTDataTable();
                    workViewDisplayTemp = new WorkViewTDS.WorkViewDisplayTempDataTable();
                    workViewSortTemp = new WorkViewTDS.WorkViewSortTempDataTable();
                    workViewConditionNew = new WorkViewTDS.WorkViewConditionNewDataTable();

                    // ... Store datasets
                    Session["workViewTDS"] = workViewTDS;

                    Session["workTypeViewDisplay"] = workTypeViewDisplay;
                    Session["workTypeViewSort"] = workTypeViewSort;
                    Session["workViewDisplayTemp"] = workViewDisplayTemp;
                    Session["workViewSortTemp"] = workViewSortTemp;
                    Session["workViewConditionNew"] = workViewConditionNew;

                }

                // StepSection1In
                wzViews.ActiveStepIndex = 0;
                StepBeginIn();
            }
            else
            {
                // Restore datasets
                workViewTDS = (WorkViewTDS)Session["workViewTDS"];

                workTypeViewDisplay = (WorkViewTDS.LFS_WORK_TYPE_VIEW_DISPLAYDataTable)Session["workTypeViewDisplay"];
                workTypeViewSort = (WorkViewTDS.LFS_WORK_TYPE_VIEW_SORTDataTable)Session["workTypeViewSort"];
                workViewDisplayTemp = (WorkViewTDS.WorkViewDisplayTempDataTable)Session["workViewDisplayTemp"];
                workViewSortTemp = (WorkViewTDS.WorkViewSortTempDataTable)Session["workViewSortTemp"];
                workViewConditionNew = (WorkViewTDS.WorkViewConditionNewDataTable)Session["workViewConditionNew"];
            }

            // control for postback
            hdfTag.Value = DateTime.Now.ToLongTimeString();
        }