internal static void AddCheckBoxAttributes(WebControl checkBoxElement, Control checkBox, FormValue <bool> checkBoxFormValue, FormValue <CommonCheckBox> radioButtonFormValue, string radioButtonListItemId, PostBack postBack, bool autoPostBack, IEnumerable <string> onClickJsMethods) { checkBoxElement.Attributes.Add("type", checkBoxFormValue != null ? "checkbox" : "radio"); checkBoxElement.Attributes.Add("name", checkBoxFormValue != null ? checkBox.UniqueID : ((FormValue)radioButtonFormValue).GetPostBackValueKey()); if (radioButtonFormValue != null) { checkBoxElement.Attributes.Add("value", radioButtonListItemId ?? checkBox.UniqueID); } if (checkBoxFormValue != null ? checkBoxFormValue.GetValue(AppRequestState.Instance.EwfPageRequestState.PostBackValues) : radioButtonFormValue.GetValue(AppRequestState.Instance.EwfPageRequestState.PostBackValues) == checkBox) { checkBoxElement.Attributes.Add("checked", "checked"); } PostBackButton.EnsureImplicitSubmission(checkBoxElement, postBack); var isSelectedRadioButton = radioButtonFormValue != null && radioButtonFormValue.GetValue(AppRequestState.Instance.EwfPageRequestState.PostBackValues) == checkBox; var postBackScript = autoPostBack && !isSelectedRadioButton ? PostBackButton.GetPostBackScript(postBack ?? EwfPage.Instance.DataUpdatePostBack, includeReturnFalse : false) : ""; var customScript = StringTools.ConcatenateWithDelimiter("; ", onClickJsMethods.ToArray()); checkBoxElement.AddJavaScriptEventScript(JsWritingMethods.onclick, StringTools.ConcatenateWithDelimiter("; ", postBackScript, customScript)); }
/// <summary> /// Gets the post back value. /// </summary> public RsFile GetPostBackValue(PostBackValueDictionary postBackValues) { if (postBackValue == null) { var value = formValue.GetValue(postBackValues); if (value == null) { return(null); } using (var ms = new MemoryStream()) { value.InputStream.CopyTo(ms); postBackValue = new RsFile(ms.ToArray(), Path.GetFileName(value.FileName), contentType: value.ContentType); } } return(postBackValue); }
/// <summary> /// Gets whether the box is checked in the post back. /// </summary> public bool IsCheckedInPostBack(PostBackValueDictionary postBackValues) { return(checkBoxFormValue != null?checkBoxFormValue.GetValue(postBackValues) : radioButtonFormValue.GetValue(postBackValues) == this); }
void ControlTreeDataLoader.LoadData() { Attributes.Add("name", UniqueID); PreRender += delegate { Attributes.Add("value", formValue.GetValue(AppRequestState.Instance.EwfPageRequestState.PostBackValues)); }; Attributes.Add("type", "hidden"); }
internal static void AddCheckBoxAttributes( WebControl checkBoxElement, Control checkBox, FormValue<bool> checkBoxFormValue, FormValue<CommonCheckBox> radioButtonFormValue, string radioButtonListItemId, PostBack postBack, bool autoPostBack, IEnumerable<string> onClickJsMethods) { checkBoxElement.Attributes.Add( "type", checkBoxFormValue != null ? "checkbox" : "radio" ); checkBoxElement.Attributes.Add( "name", checkBoxFormValue != null ? checkBox.UniqueID : ( (FormValue)radioButtonFormValue ).GetPostBackValueKey() ); if( radioButtonFormValue != null ) checkBoxElement.Attributes.Add( "value", radioButtonListItemId ?? checkBox.UniqueID ); if( checkBoxFormValue != null ? checkBoxFormValue.GetValue( AppRequestState.Instance.EwfPageRequestState.PostBackValues ) : radioButtonFormValue.GetValue( AppRequestState.Instance.EwfPageRequestState.PostBackValues ) == checkBox ) checkBoxElement.Attributes.Add( "checked", "checked" ); PostBackButton.EnsureImplicitSubmission( checkBoxElement, postBack ); var isSelectedRadioButton = radioButtonFormValue != null && radioButtonFormValue.GetValue( AppRequestState.Instance.EwfPageRequestState.PostBackValues ) == checkBox; var postBackScript = autoPostBack && !isSelectedRadioButton ? PostBackButton.GetPostBackScript( postBack ?? EwfPage.Instance.DataUpdatePostBack, includeReturnFalse: false ) : ""; var customScript = StringTools.ConcatenateWithDelimiter( "; ", onClickJsMethods.ToArray() ); checkBoxElement.AddJavaScriptEventScript( JsWritingMethods.onclick, StringTools.ConcatenateWithDelimiter( "; ", postBackScript, customScript ) ); }
void ControlTreeDataLoader.LoadData() { Attributes.Add("name", UniqueID); PreRender += delegate { EwfTextBox.AddTextareaValue(this, formValue.GetValue(AppRequestState.Instance.EwfPageRequestState.PostBackValues)); }; }
void ControlTreeDataLoader.LoadData() { var isTextarea = rows > 1; textBox = new WebControl(isTextarea ? HtmlTextWriterTag.Textarea : HtmlTextWriterTag.Input); PreRender += delegate { if (!isTextarea) { textBox.Attributes.Add("type", masksCharacters ? "password" : "text"); } textBox.Attributes.Add("name", UniqueID); if (isTextarea) { textBox.Attributes.Add("rows", rows.ToString()); } if (maxLength.HasValue) { textBox.Attributes.Add("maxlength", maxLength.Value.ToString()); } if (readOnly) { textBox.Attributes.Add("readonly", "readonly"); } if (disableBrowserAutoComplete || autoCompleteService != null) { textBox.Attributes.Add("autocomplete", "off"); } if (suggestSpellCheck.HasValue) { textBox.Attributes.Add("spellcheck", suggestSpellCheck.Value.ToString().ToLower()); } var value = formValue.GetValue(AppRequestState.Instance.EwfPageRequestState.PostBackValues); var valueOrWatermark = watermarkText.Any() && !value.Any() ? watermarkText : value; if (isTextarea) { textBox.Controls.Add(new Literal { Text = HttpUtility.HtmlEncode(GetTextareaValue(valueOrWatermark)) }); } else if (!masksCharacters) { textBox.Attributes.Add("value", valueOrWatermark); } }; Controls.Add(textBox); if (watermarkText.Any()) { textBox.AddJavaScriptEventScript(JsWritingMethods.onfocus, "if( value == '" + watermarkText + "' ) value = ''"); textBox.AddJavaScriptEventScript(JsWritingMethods.onblur, "if( value == '' ) value = '" + watermarkText + "'"); EwfPage.Instance.ClientScript.RegisterOnSubmitStatement( GetType(), UniqueID + "watermark", "$( '#" + textBox.ClientID + "' ).filter( function() { return this.value == '" + watermarkText + "'; } ).val( '' )"); } if (!isTextarea || autoPostBack || (autoCompleteService != null && autoCompleteOption != AutoCompleteOption.NoPostBack)) { action.AddToPageIfNecessary(); } if (!isTextarea) { PreRender += delegate { SubmitButton.EnsureImplicitSubmissionAction( this, action, autoPostBack || (autoCompleteService != null && autoCompleteOption == AutoCompleteOption.PostBackOnTextChangeAndItemSelect)); } } ; if (autoPostBack || (autoCompleteService != null && autoCompleteOption == AutoCompleteOption.PostBackOnTextChangeAndItemSelect)) { PreRender += delegate { // Use setTimeout to prevent keypress and change from *both* triggering post-backs at the same time when Enter is pressed after a text change. textBox.AddJavaScriptEventScript(JsWritingMethods.onchange, "setTimeout( function() { " + action.GetJsStatements() + " }, 0 )"); } } ; if (ToolTip != null || ToolTipControl != null) { new ToolTip(ToolTipControl ?? EnterpriseWebFramework.Controls.ToolTip.GetToolTipTextControl(ToolTip), textBox); } } string ControlWithJsInitLogic.GetJsInitStatements() { var script = new StringBuilder(); if (watermarkText.Any()) { var restorationStatement = "$( '#" + textBox.ClientID + "' ).filter( function() { return this.value == ''; } ).val( '" + watermarkText + "' );"; // The first line is for bfcache browsers; the second is for all others. See http://stackoverflow.com/q/1195440/35349. script.Append("$( window ).on( 'pagehide', function() { " + restorationStatement + " } );"); script.Append(restorationStatement); } if (autoCompleteService != null) { const int delay = 250; // Default delay is 300 ms. const int minCharacters = 3; var autocompleteOptions = new List <Tuple <string, string> >(); autocompleteOptions.Add(Tuple.Create("delay", delay.ToString())); autocompleteOptions.Add(Tuple.Create("minLength", minCharacters.ToString())); autocompleteOptions.Add(Tuple.Create("source", "'" + autoCompleteService.GetUrl() + "'")); if (autoCompleteOption != AutoCompleteOption.NoPostBack) { var handler = "function( event, ui ) {{ $( '#{0}' ).val( ui.item.value ); {1} return false; }}".FormatWith(textBox.ClientID, action.GetJsStatements()); autocompleteOptions.Add(Tuple.Create("select", handler)); } script.Append( @"$( '#" + textBox.ClientID + "' ).autocomplete( {{ {0} }} );".FormatWith( autocompleteOptions.Select(o => "{0}: {1}".FormatWith(o.Item1, o.Item2)).GetCommaDelimitedStringFromCollection())); } return(script.ToString()); } FormValue FormValueControl.FormValue { get { return(formValue); } }
void ControlTreeDataLoader.LoadData() { if (postBack != null || AutoPostBack) { EwfPage.Instance.AddPostBack(postBack ?? EwfPage.Instance.DataUpdatePostBack); } PreRender += delegate { if (highlightWhenChecked && checkBoxFormValue.GetValue(AppRequestState.Instance.EwfPageRequestState.PostBackValues)) { CssClass = CssClass.ConcatenateWithSpace("checkedChecklistCheckboxDiv"); } }; var table = TableOps.CreateUnderlyingTable(); table.CssClass = "ewfBlockCheckBox"; checkBox = new WebControl(HtmlTextWriterTag.Input); PreRender += delegate { EwfCheckBox.AddCheckBoxAttributes(checkBox, this, checkBoxFormValue, radioButtonFormValue, radioButtonListItemId, postBack, AutoPostBack, onClickJsMethods); }; var checkBoxCell = new TableCell().AddControlsReturnThis(checkBox); checkBoxCell.Style.Add("width", "13px"); var row = new TableRow(); row.Cells.Add(checkBoxCell); var labelControl = new HtmlGenericControl("label") { InnerText = label }; row.Cells.Add(new TableCell().AddControlsReturnThis(labelControl)); PreRender += (s, e) => labelControl.Attributes.Add("for", checkBox.ClientID); table.Rows.Add(row); if (NestedControls.Any()) { var nestedControlRow = new TableRow(); nestedControlRow.Cells.Add(new TableCell()); nestedControlRow.Cells.Add(new TableCell().AddControlsReturnThis(NestedControls)); table.Rows.Add(nestedControlRow); if (!NestedControlsAlwaysVisible) { CheckBoxToControlArrayDisplayLink.AddToPage(this, true, nestedControlRow); } } Controls.Add(table); if (ToolTip != null || ToolTipControl != null) { new ToolTip(ToolTipControl ?? EnterpriseWebFramework.Controls.ToolTip.GetToolTipTextControl(ToolTip), label.Length > 0 ? (Control)labelControl : checkBox); } }
void ControlTreeDataLoader.LoadData() { action.AddToPageIfNecessary(); PreRender += delegate { if (setup.HighlightedWhenChecked && checkBoxFormValue.GetValue(AppRequestState.Instance.EwfPageRequestState.PostBackValues)) { CssClass = CssClass.ConcatenateWithSpace("checkedChecklistCheckboxDiv"); } }; var table = TableOps.CreateUnderlyingTable(); table.CssClass = "ewfBlockCheckBox"; checkBox = new WebControl(HtmlTextWriterTag.Input); PreRender += delegate { EwfCheckBox.AddCheckBoxAttributes( checkBox, this, checkBoxFormValue, radioButtonFormValue, radioButtonListItemId, action, setup.TriggersPostBackWhenCheckedOrUnchecked, jsClickHandlerStatementLists.SelectMany(i => i())); }; var checkBoxCell = new TableCell().AddControlsReturnThis(checkBox); checkBoxCell.Style.Add("width", "13px"); var row = new TableRow(); row.Cells.Add(checkBoxCell); var labelControl = new HtmlGenericControl("label") { InnerText = label }; row.Cells.Add(new TableCell().AddControlsReturnThis(labelControl)); PreRender += (s, e) => labelControl.Attributes.Add("for", checkBox.ClientID); table.Rows.Add(row); if (nestedControls.Any()) { var nestedControlRow = new TableRow(); nestedControlRow.Cells.Add(new TableCell()); nestedControlRow.Cells.Add(new TableCell().AddControlsReturnThis(nestedControls)); table.Rows.Add(nestedControlRow); if (!setup.NestedControlsAlwaysVisible) { CheckBoxToControlArrayDisplayLink.AddToPage(this, true, nestedControlRow); } } Controls.Add(table); if (ToolTip != null || ToolTipControl != null) { new Controls.ToolTip( ToolTipControl ?? EnterpriseWebFramework.Controls.ToolTip.GetToolTipTextControl(ToolTip), label.Length > 0 ? (Control)labelControl : checkBox); } }
void ControlTreeDataLoader.LoadData() { var isTextarea = rows > 1; textBox = new WebControl(isTextarea ? HtmlTextWriterTag.Textarea : HtmlTextWriterTag.Input); PreRender += delegate { if (!isTextarea) { textBox.Attributes.Add("type", masksCharacters ? "password" : "text"); } textBox.Attributes.Add("name", UniqueID); if (isTextarea) { textBox.Attributes.Add("rows", rows.ToString()); } if (maxLength.HasValue) { textBox.Attributes.Add("maxlength", maxLength.Value.ToString()); } if (readOnly) { textBox.Attributes.Add("readonly", "readonly"); } if (disableBrowserAutoComplete || autoCompleteService != null) { textBox.Attributes.Add("autocomplete", "off"); } if (suggestSpellCheck.HasValue) { textBox.Attributes.Add("spellcheck", suggestSpellCheck.Value.ToString().ToLower()); } var value = formValue.GetValue(AppRequestState.Instance.EwfPageRequestState.PostBackValues); var valueOrWatermark = watermarkText.Any() && !value.Any() ? watermarkText : value; if (isTextarea) { AddTextareaValue(textBox, valueOrWatermark); } else if (!masksCharacters) { textBox.Attributes.Add("value", valueOrWatermark); } }; Controls.Add(textBox); if (watermarkText.Any()) { textBox.AddJavaScriptEventScript(JsWritingMethods.onfocus, "if( value == '" + watermarkText + "' ) value = ''"); textBox.AddJavaScriptEventScript(JsWritingMethods.onblur, "if( value == '' ) value = '" + watermarkText + "'"); EwfPage.Instance.ClientScript.RegisterOnSubmitStatement( GetType(), UniqueID + "watermark", "$( '#" + textBox.ClientID + "' ).filter( function() { return this.value == '" + watermarkText + "'; } ).val( '' )"); } var jsNeededForImplicitSubmission = postBack != null || autoPostBack || (autoCompleteService != null && autoCompleteOption == AutoCompleteOption.PostBackOnTextChangeAndItemSelect); if (postBack == null && (autoPostBack || (autoCompleteService != null && autoCompleteOption != AutoCompleteOption.NoPostBack))) { postBack = EwfPage.Instance.DataUpdatePostBack; } if (postBack != null) { EwfPage.Instance.AddPostBack(postBack); } PreRender += delegate { PostBackButton.EnsureImplicitSubmission(this, jsNeededForImplicitSubmission ? postBack : null); }; if (autoPostBack || (autoCompleteService != null && autoCompleteOption == AutoCompleteOption.PostBackOnTextChangeAndItemSelect)) { PreRender += delegate { // Use setTimeout to prevent keypress and change from *both* triggering post-backs at the same time when Enter is pressed after a text change. textBox.AddJavaScriptEventScript( JsWritingMethods.onchange, "setTimeout( function() { " + PostBackButton.GetPostBackScript(postBack, includeReturnFalse: false) + "; }, 0 )"); }; } if (ToolTip != null || ToolTipControl != null) { new ToolTip(ToolTipControl ?? EnterpriseWebFramework.Controls.ToolTip.GetToolTipTextControl(ToolTip), textBox); } }