protected new void Page_Init(object sender, EventArgs e)
        {
            cmbStandardSet.OnClientChange = "GetSelectedLevelText()";

            Master.Search += SearchHandler;
            base.Page_Init(sender, e);
            _currentViewByValue = string.Empty;
            _enviromentParameter = new EnvironmentParametersFactory(AppSettings.ConnectionStringName).GetEnvironmentParameters();
            _loggedOnUserRoleName = SessionObject.LoggedInUser.Roles[0].RoleName;
            _loggedOnUser = SessionObject.LoggedInUser;

            _excelIgnoredColumns.Add("EncryptedID");
            _excelIgnoredColumns.Add("WorksheetId");
            _excelIgnoredColumns.Add("StandardId");
            _excelIgnoredColumns.Add("Included");
            _excelIgnoredColumns.Add("Total");
            _excelIgnoredColumns.Add("Excluded");
            _excelIgnoredColumns.Add("StandardLevel");
            _excelIgnoredColumns.Add("ScoreColumnA");
            _excelIgnoredColumns.Add("ScoreColumnB");
            _excelIgnoredColumns.Add("ScoreColumnC");
            _excelIgnoredColumns.Add("ScoreColumnD");
            _excelIgnoredColumns.Add("ScoreColumnE");
            //_excelIgnoredColumns.Add("CountA");
            //_excelIgnoredColumns.Add("CountB");
            //_excelIgnoredColumns.Add("CountC");
            //_excelIgnoredColumns.Add("CountD");
            //_excelIgnoredColumns.Add("CountE");
        }
		/// <summary>
		/// Builds the QuestionSearchCriteria. Used both from Search Button and from Service
		/// </summary>
		public static AddendumSearchCriteriaV2 BuildSearchCriteriaObject(ThinkgateUser user, CriteriaController criteriaController, string requestedSortField = null)
		{

			/* Sort */
			string sortField = null;
			NameValue nvSortField = SortFields().Find(x => x.Name == requestedSortField);   // ensure that the user given value for sort is in the defined list of options
			if (nvSortField != null) sortField = nvSortField.Value;

			/* Item Banks - Remove from master list based on filter if given */
			var itemBanks = ItemBankMasterList.GetItemBanksForUser(user);

            if (TestCategory != null && TestCategory == AssessmentCategories.District.ToString())
            {
                for (var rowIndex = itemBanks.Rows.Count - 1; rowIndex >= 0; rowIndex--)
                {
                    if (itemBanks.Rows[rowIndex]["Label"].ToString() == "Personal")
                    { itemBanks.Rows[rowIndex].Delete(); }
                }
            }

            var selectedItemBanks = criteriaController.ParseCriteria<CheckBoxList.ValueObject>("ItemBank").Select(x => x.Text);
			if (selectedItemBanks.Any()) itemBanks.DeleteByLabel(selectedItemBanks);

			/* Text Search */
			string searchText = string.Empty;
			string searchOption = string.Empty;
			var txtSearchList = criteriaController.ParseCriteria<TextWithDropdown.ValueObject>("TextSearch");
			if (txtSearchList.Count > 0)
			{
				// we ensure that the value the user gave us for text search type is a valid option
				var confirmedOption = TextSearchDropdownValues().Find(x => x.Name == txtSearchList[0].Option) ?? TextSearchDropdownValues().First();
				if (!String.IsNullOrEmpty(txtSearchList[0].Text))
				{
					searchText = txtSearchList[0].Text;
					searchOption = confirmedOption.Value;
				}
			}

			/* Courses */
			var selectedGrades = criteriaController.ParseCriteria<CheckBoxList.ValueObject>("Grade").Select(x => x.Text).ToList();
			var selectedSubjects = criteriaController.ParseCriteria<CheckBoxList.ValueObject>("Subject").Select(x => x.Text).ToList();
			var selectedCourses = criteriaController.ParseCriteria<CheckBoxList.ValueObject>("Course").Select(x => x.Text).ToList();
			var selectedStandardSets = new drGeneric_String(criteriaController.ParseCriteria<CheckBoxList.ValueObject>("StandardSet").Select(x => x.Text));     // take straight to drGeneric_String because it's going to SQL
			var filteredCourses = CourseMasterList.GetStandardCoursesForUser(user).FilterByGradesSubjectsStandardSetsAndCourse(selectedGrades, selectedSubjects, selectedStandardSets, selectedCourses);


			/* Type/Genre */
			var selectedAddendumGenres = new drGeneric_String();
			var selectedAddendumTypes = new drGeneric_String();
			var selectedTypesGenres = criteriaController.ParseCriteria<AddendumType.ValueObject>("AddendumType");
			foreach (var selectedTypesGenre in selectedTypesGenres)
			{
				if (selectedTypesGenre.Genre != null)
				{
					selectedAddendumGenres.Add(selectedTypesGenre.Genre);
				}
				else
				{
					selectedAddendumTypes.Add(selectedTypesGenre.Text);
				}
			}
			if (selectedAddendumGenres.Count > 0)
				selectedAddendumTypes.Add("Passage");


		    var selectedExpirationStatus = criteriaController.ParseCriteria<DropDownList.ValueObject>("ExpirationStatus").FirstOrDefault() != null ? 
                criteriaController.ParseCriteria<DropDownList.ValueObject>("ExpirationStatus").FirstOrDefault().Value : "I";
            if (!ShowExpiredItems)
            {
                selectedExpirationStatus = "E";

            }
            drGeneric_String_String selectedExpirationDateRange = new drGeneric_String_String();
            foreach (var val in criteriaController.ParseCriteria<DateRange.ValueObject>("ExpirationDateRange"))
            {
                selectedExpirationDateRange.Add(val.Type == "Start" ? "CreatedDateStart" : "CreatedDateEnd", val.Date);
            }


			/* Build Criteria Object */
            var asc = new AddendumSearchCriteriaV2()
                                             {
                                                 ItemBanks = itemBanks,
                                                 CourseList = filteredCourses,
                                                 AddendumType = selectedAddendumTypes,
                                                 AddendumGenre = selectedAddendumGenres,
                                                 UserAccessItemReservations = "",
                                                 Text = searchText,
                                                 TextOpt = searchOption,                                                 
                                                 SortKeyword = sortField,
                                                 courseSelected = selectedCourses.Count > 0 ? true : false,
                                                 ExpirationStatus = selectedExpirationStatus,
                                                 ExpirationDateRange = selectedExpirationDateRange
                                             };

			return asc;
		}
        public static List<Thinkgate.Base.Classes.Resource> SearchResourcesWithCriteria(ThinkgateUser user, CriteriaController criteriaController)
        {
            var selectedCategories = criteriaController.ParseCriteria<CheckBoxList.ValueObject>("Category").Select(x => x.Value);
            var selectedTypes = criteriaController.ParseCriteria<CheckBoxList.ValueObject>("Type").Select(x => x.Value);
            var selectedSubTypes = criteriaController.ParseCriteria<CheckBoxList.ValueObject>("Subtype").Select(x => x.Value);

            string resourceName = string.Empty;
            var resourceNameList = criteriaController.ParseCriteria<E3Criteria.Text.ValueObject>("ResourceName");
            if (resourceNameList.Count > 0) resourceName = resourceNameList[0].Text;

            string searchText = string.Empty;
            string searchOption = string.Empty;
            var txtSearchList = criteriaController.ParseCriteria<E3Criteria.TextWithDropdown.ValueObject>("TextSearch");
            if (txtSearchList.Count > 0)
            {
                var confirmedOption = TextSearchDropdownValues().Find(x => x.Name == txtSearchList[0].Option) ?? TextSearchDropdownValues().First();
                if (!String.IsNullOrEmpty(txtSearchList[0].Text))
                {
                    searchText = txtSearchList[0].Text;
                    searchOption = confirmedOption.Value;
                }
            }
            var selectedStandards = new ArrayList();
            var associationType = string.Empty;
            var associationField1 = string.Empty;
            var associationField2 = string.Empty;
            var associationField3 = string.Empty;
            var associatedCurriculum = criteriaController.ParseCriteria<Curriculum.ValueObject>("Curriculum");
            var associatedStandards = criteriaController.ParseCriteria<E3Criteria.Associations.Standards.ValueObject>("Standards");
            var associatedClasses = criteriaController.ParseCriteria<E3Criteria.Associations.Classes.ValueObject>("Classes");
            var associatedDocuments = criteriaController.ParseCriteria<E3Criteria.Associations.Documents.ValueObject>("Documents");
            var associatedSchools = criteriaController.ParseCriteria<E3Criteria.Associations.Schools.ValueObject>("Schools");
            var associatedStudents = criteriaController.ParseCriteria<E3Criteria.Associations.Students.ValueObject>("Students");
            var associatedTeachers = criteriaController.ParseCriteria<E3Criteria.Associations.Teachers.ValueObject>("Teachers"); 
            if (associatedCurriculum.Count > 0)
            {
                associationType = "Curriculum";
                associationField1 = associatedCurriculum[0].Grade;
                associationField2 = associatedCurriculum[0].Subject;
                associationField3 = associatedCurriculum[0].Curriculum;
            }
            else if (associatedStandards.Count > 0 && associatedStandards[0].Standards != null && associatedStandards[0].Standards.Count > 0)
            {
                associationType = "Standards"; 
                selectedStandards = associatedStandards[0].Standards;
            }
            else if (associatedClasses.Count > 0)
            {
                associationType = "Classes";
                associationField1 = associatedClasses[0].Grade;
                associationField2 = associatedClasses[0].Subject;
                associationField3 = associatedClasses[0].Course;
            }
            else if (associatedDocuments.Count > 0)
            {
                associationType = "Documents";
                associationField1 = associatedDocuments[0].TemplateType;
                associationField2 = associatedDocuments[0].TemplateName;
                associationField3 = associatedDocuments[0].DocumentName;
            }
            else if (associatedSchools.Count > 0)
            {
                associationType = "Schools";
                associationField1 = associatedSchools[0].SchoolType;
                associationField2 = associatedSchools[0].School;
                associationField3 = associatedSchools[0].SchoolId;
            }
            else if (associatedStudents.Count > 0)
            {
                associationType = "Students";
                associationField1 = associatedStudents[0].Name;
                associationField2 = associatedStudents[0].Id;
                associationField3 = associatedStudents[0].Grade;
            }
            else if (associatedTeachers.Count > 0)
            {
                associationType = "Teachers";
                associationField1 = associatedTeachers[0].Name;
                associationField2 = associatedTeachers[0].UserType;
                associationField3 = associatedTeachers[0].UserId;
            }
            
            
           

            return Thinkgate.Base.Classes.Resource.SearchAdvanced(selectedCategories, selectedTypes, selectedSubTypes, resourceName, searchText, searchOption,
                associationType, associationField1, associationField2, associationField3, selectedStandards);
        }
        /// <summary>
        /// Builds the QuestionSearchCriteria. Used both from Search Button and from Service
        /// </summary>
        public static ItemImageSearchCriteriaV2 BuildSearchCriteriaObject(ThinkgateUser user, CriteriaController criteriaController, string requestedSortField = null)
        {
            
            /* Sort */
            string sortField = null;
            NameValue nvSortField = SortFields().Find(x => x.Name == requestedSortField);   // ensure that the user given value for sort is in the defined list of options
            if (nvSortField != null) sortField = nvSortField.Value;

            /* Item Banks - Remove from master list based on filter if given */
            var itemBanks = ItemBankMasterList.GetItemBanksForUser(user);
            var selectedItemBanks = criteriaController.ParseCriteria<CheckBoxList.ValueObject>("ItemBank").Select(x => x.Text);
            if (selectedItemBanks.Any()) itemBanks.DeleteByLabel(selectedItemBanks);

            /* Text Search */
            string searchText = string.Empty;
            string searchOption = string.Empty;
            var txtSearchList = criteriaController.ParseCriteria<TextWithDropdown.ValueObject>("TextSearch");
            if (txtSearchList.Count > 0)
            {
                // we ensure that the value the user gave us for text search type is a valid option
                var confirmedOption = TextSearchDropdownValues().Find(x => x.Name == txtSearchList[0].Option) ?? TextSearchDropdownValues().First();
                if (!String.IsNullOrEmpty(txtSearchList[0].Text))
                {
                    searchText = txtSearchList[0].Text;
                    searchOption = confirmedOption.Value;
                }
            }

            /* Courses */
            var selectedGrades = criteriaController.ParseCriteria<CheckBoxList.ValueObject>("Grade").Select(x => x.Text).ToList();
            var selectedSubjects = criteriaController.ParseCriteria<CheckBoxList.ValueObject>("Subject").Select(x => x.Text).ToList();
            var selectedCourses = criteriaController.ParseCriteria<CheckBoxList.ValueObject>("Course").Select(x => x.Text).ToList();
            var selectedStandardSets = new drGeneric_String(criteriaController.ParseCriteria<CheckBoxList.ValueObject>("StandardSet").Select(x => x.Text));     // take straight to drGeneric_String because it's going to SQL
            var filteredCourses = CourseMasterList.GetStandardCoursesForUser(user).FilterByGradesSubjectsStandardSetsAndCourse(selectedGrades, selectedSubjects, selectedStandardSets, selectedCourses);

            var selectedExpirationStatus = criteriaController.ParseCriteria<DropDownList.ValueObject>("ExpirationStatus").FirstOrDefault() != null ?
            criteriaController.ParseCriteria<DropDownList.ValueObject>("ExpirationStatus").FirstOrDefault().Value : "I";
            if (!ShowExpiredItems)
            {
                selectedExpirationStatus = "E";

            }
            drGeneric_String_String selectedExpirationDateRange = new drGeneric_String_String();
            foreach (var val in criteriaController.ParseCriteria<DateRange.ValueObject>("ExpirationDateRange"))
            {
                selectedExpirationDateRange.Add(val.Type == "Start" ? "CreatedDateStart" : "CreatedDateEnd", val.Date);
            }




            /* Build Criteria Object */
            var asc = new ItemImageSearchCriteriaV2()
                                             {
                                                 ItemBanks = itemBanks,
                                                 StandardCourses = filteredCourses,
                                                 TextWords = searchText,
                                                 TextWordsOpt = searchOption,
                                                 GradeLimited = selectedGrades.Count > 0,
                                                 SubjectLimited = selectedSubjects.Count > 0,
                                                 CourseLimited = selectedCourses.Count > 0,
                                                 SortBy = sortField == "ItemBank" || sortField == "Standard"
                                                     ? null
                                                     : sortField,
                                                 ExpirationStatus = selectedExpirationStatus,
                                                 ExpirationDateRange = selectedExpirationDateRange
                                             };
            
            return asc;
        }
		/// <summary>
		/// This is in case a user is updating his/her own information, so that the information
		/// will persist throughout the user experience without logging out and back in.
		/// 
		/// </summary>
		/// <param name="user"></param>
		public void UpdateUserObject(ThinkgateUser user)
		{
			if (ApplicationUser != null && ApplicationUser.UserId == user.UserId) ApplicationUser = user;
			if (ImpersonatingUser != null && ImpersonatingUser.UserId == user.UserId) ImpersonatingUser = user;
			if (LoggedInUser != null && LoggedInUser.UserId == user.UserId) LoggedInUser = user;
			if (SelectedUser != null && SelectedUser.UserId == user.UserId) SelectedUser = user;

		}