/// <summary> /// On PreRender. /// </summary> protected override void OnPreRender(EventArgs e) { base.OnPreRender(e); if (StopProcessing) { return; } else if (!string.IsNullOrEmpty(ErrorText)) { pnlLabel.Visible = true; lblError.Visible = true; return; } // Search condition string searchText = SearchText; if (!RequestHelper.IsPostBack()) { searchText = QueryHelper.GetString("searchtext", SearchText); } txtSearch.Text = searchText; // Add search condition if (!string.IsNullOrEmpty(searchText)) { // Avoid SQL injection searchText = SqlHelper.EscapeQuotes(searchText); string[] columns = SearchColumn.Split(new[] { ';', ',' }, StringSplitOptions.RemoveEmptyEntries); string columnsWhere = string.Empty; foreach (string column in columns) { columnsWhere = SqlHelper.AddWhereCondition(columnsWhere, column + " LIKE N'%" + SqlHelper.EscapeLikeText(searchText) + "%'", "OR"); } repItems.WhereCondition = SqlHelper.AddWhereCondition(repItems.WhereCondition, columnsWhere); } // Handle TOP N for first load if (repItems.TopN == 0) { int currentPage = pgrItems.CurrentPage; // Minimum is first group int currentGroup = currentPage / pgrItems.GroupSize + ((currentPage % pgrItems.GroupSize > 0) ? 1 : 0); int topN = currentGroup * pgrItems.GroupSize * pgrItems.DefaultPageSize + pgrItems.DefaultPageSize; repItems.TopN = topN; } if (!String.IsNullOrEmpty(SelectedItem)) { var clearSelectedItemScript = String.Empty; if (!RememberSelectedItem) { // Clear selected item value if remembering is disabled (category change, paging, ...) SelectedItem = string.Empty; clearSelectedItemScript = @" selectedFlatItem = null; selectedValue = null; selectedItemName = null;"; } // Get description string description = RaiseOnItemSelected(SelectedItem); // Create startup script which optionally clears selected item and updates description if selected item is not removed var startupScript = clearSelectedItemScript + "\r\n" + callBackHandlerFunction + "('" + description + "');"; // Register startup script ScriptHelper.RegisterStartupScript(this, typeof(string), ClientID + "_StartupScript", ScriptHelper.GetScript(startupScript)); } // Different no records messages based on search lblNoRecords.Text = GetString(String.IsNullOrEmpty(SearchText) ? NoRecordsMessage : NoRecordsSearchMessage); repItems.ReloadData(true); // Show no results found if (!repItems.HasData()) { pnlLabel.Visible = true; lblNoRecords.Visible = true; } // Set focus on the search text box when required if (!searchExecuted && UseStartUpFocus) { RegisterFocusScript(); } }
/// <summary> /// On PreRender. /// </summary> protected override void OnPreRender(EventArgs e) { base.OnPreRender(e); if (this.StopProcessing) { return; } else if (!string.IsNullOrEmpty(ErrorText)) { pnlLabel.Visible = true; lblError.Visible = true; return; } // Search condition string searchText = SearchText; if (!RequestHelper.IsPostBack()) { searchText = QueryHelper.GetString("searchtext", SearchText); } txtSearch.Text = searchText; // Add search condition if (!string.IsNullOrEmpty(searchText)) { // Avoid SQL injection searchText = SqlHelperClass.GetSafeQueryString(searchText, false); string[] columns = SearchColumn.Split(new char[] { ';', ',' }, StringSplitOptions.RemoveEmptyEntries); string columnsWhere = string.Empty; foreach (string column in columns) { columnsWhere = SqlHelperClass.AddWhereCondition(columnsWhere, column + " LIKE N'%" + searchText + "%'", "OR"); } repItems.WhereCondition = SqlHelperClass.AddWhereCondition(repItems.WhereCondition, columnsWhere); } // Handle TOP N for first load if (repItems.TopN == 0) { int currentPage = pgrItems.CurrentPage; // Minimum is first group int currentGroup = currentPage / pgrItems.GroupSize + ((currentPage % pgrItems.GroupSize > 0) ? 1 : 0); int topN = currentGroup * pgrItems.GroupSize * pgrItems.PageSize + pgrItems.PageSize; repItems.TopN = topN; } // Clear selected item value if remembering is disabled (category change, paginng, ...) if ((!this.RememberSelectedItem) && !String.IsNullOrEmpty(this.SelectedItem)) { this.SelectedItem = string.Empty; // Get updated description string description = RaiseOnItemSelected(this.SelectedItem); // Clear client side values and update description ScriptHelper.RegisterStartupScript(this, typeof(string), "ClearSelectedItem", ScriptHelper.GetScript( "selectedFlatItem = null;" + "selectedValue = null;" + "selectedItemName = null;" + callBackHandlerFunction + "('" + description + "');" )); } // Different no records messages based on search if (String.IsNullOrEmpty(this.SearchText)) { lblNoRecords.Text = GetString(this.NoRecordsMessage); } else { lblNoRecords.Text = GetString(this.NoRecordsSearchMessage); } repItems.ReloadData(true); // Show no results found if (!repItems.HasData()) { pnlLabel.Visible = true; lblNoRecords.Visible = true; } // Set focus on the search text box when required if (!searchExecuted && this.UseStartUpFocus) { RegisterFocusScript(); } }