/// <summary> /// Create javascript function, CommitSelection which is called when OK button is clicked /// </summary> /// <remarks></remarks> public virtual void RegisterJSCommitSelection() { string emptyValue = ""; string emptyDisplayText = ""; string target = ""; if (!string.IsNullOrEmpty(Page.Request["Target"])) { target = ((BaseApplicationPage)this.Page).GetDecryptedURLParameter("Target"); } if (!string.IsNullOrEmpty(Page.Request["EmptyValue"])) { emptyValue = ((BaseApplicationPage)this.Page).GetDecryptedURLParameter("EmptyValue"); } if (!string.IsNullOrEmpty(Page.Request["EmptyDisplayText"])) { emptyDisplayText = ((BaseApplicationPage)this.Page).GetDecryptedURLParameter("EmptyDisplayText"); } string qsSelectionID = ""; BaseClasses.Web.UI.WebControls.QuickSelector qsSelection = (BaseClasses.Web.UI.WebControls.QuickSelector)BaseClasses.Utils.MiscUtils.FindControlRecursively(this.Page, "QSSelection"); if (qsSelection != null) { qsSelectionID = qsSelection.ClientID; } String csName = "CommitSelection"; Type csType = this.GetType(); // Get a ClientScriptManager reference from the Page class. // Create CommitSelection function. QSSelection has no selected items, Update the target control to be --PLEASE_SELECT-- ClientScriptManager cs = Page.ClientScript; if (!cs.IsClientScriptBlockRegistered(csType, csName)) { System.Text.StringBuilder csText = new System.Text.StringBuilder(); string valueID = qsSelectionID + "_Value"; csText.AppendLine("<script type=\"text/javascript\"> function CommitSelection() {"); csText.AppendLine(" var w = getParentWindow();"); csText.AppendLine(" if (w == window) {return;}"); csText.AppendLine(" var listItems = new Array()"); csText.AppendLine(" var valCtrl = document.getElementById('" + valueID + "');"); csText.AppendLine(" if (valCtrl.value != '') {"); csText.AppendLine(" listItems = JSON.parse(valCtrl.value).List;"); csText.AppendLine(" }"); csText.AppendLine(" if (listItems.length == 0){"); csText.AppendLine(" w.updateQuickSelectorItem('" + target + "', '" + emptyValue + "', '" + emptyDisplayText + "', 'Replace', true);"); csText.AppendLine(" }"); csText.AppendLine(" else {"); csText.AppendLine(" w.updateQuickSelectorItems('" + target + "', listItems, 'Replace', true);"); csText.AppendLine(" } "); csText.AppendLine("} "); csText.AppendLine("</script>"); cs.RegisterClientScriptBlock(csType, csName, csText.ToString()); } }
/// <summary> /// Create javascript function, ClearSelection which is called when Clear button is clicked /// </summary> /// <remarks></remarks> public virtual void RegisterJSClearSelection() { bool multiSelection = false; if (!string.IsNullOrEmpty(Page.Request["Mode"])) { multiSelection = (this.Page as BaseApplicationPage).GetDecryptedURLParameter("Mode") == "FieldFilterMultiSelection"; } // qsSelectionID is a special control. It is used to remember the current selection(s). // It is not shown on the layout of Design Mode. But you can see it by right-clicking on Design Mode and followed by Page Directives... string qsSelectionID = ""; BaseClasses.Web.UI.WebControls.QuickSelector qsSelection = (BaseClasses.Web.UI.WebControls.QuickSelector)BaseClasses.Utils.MiscUtils.FindControlRecursively(this.Page, "QSSelection"); if (qsSelection != null) { qsSelectionID = qsSelection.ClientID; } String csName = "ClearSelection"; Type csType = this.GetType(); // Get a ClientScriptManager reference from the Page class. ClientScriptManager cs = Page.ClientScript; if (!cs.IsClientScriptBlockRegistered(csType, csName)) { System.Text.StringBuilder csText = new System.Text.StringBuilder(); csText.AppendLine("<script type=\"text/javascript\"> function ClearSelection() {"); // Clear the selection from QSSelection control csText.AppendLine("updateQuickSelectorItems('" + qsSelectionID + "', new Array(), 'Replace', false);"); if (multiSelection) { // if it is multi selection, remove clear the row hightlight by changing the class name. csText.AppendLine("replaceClassName('tr', 'QStrSelected', 'QStr');"); } else { // if it is single selection, close the popup. csText.AppendLine("CommitSelection();"); } csText.AppendLine("} "); csText.AppendLine("</script>"); cs.RegisterClientScriptBlock(csType, csName, csText.ToString()); } }