internal void SetUpClickableControl(WebControl clickableControl) { if (resource == null && postBack == null && script == "") { return; } clickableControl.CssClass = clickableControl.CssClass.ConcatenateWithSpace("ewfClickable"); if (resource != null && EwfPage.Instance.IsAutoDataUpdater) { postBack = EwfLink.GetLinkPostBack(resource); resource = null; } Func <string> scriptGetter; if (resource != null) { scriptGetter = () => "location.href = '" + EwfPage.Instance.GetClientUrl(resource.GetUrl()) + "'; return false"; } else if (postBack != null) { EwfPage.Instance.AddPostBack(postBack); scriptGetter = () => PostBackButton.GetPostBackScript(postBack); } else { scriptGetter = () => script; } // Defer script generation until after all controls have IDs. EwfPage.Instance.PreRender += delegate { clickableControl.AddJavaScriptEventScript(JsWritingMethods.onclick, scriptGetter()); }; }
void ControlTreeDataLoader.LoadData() { var url = ""; if (destinationResourceInfo != null && !(destinationResourceInfo.AlternativeMode is DisabledResourceMode)) { url = destinationResourceInfo.GetUrl(); Attributes.Add("href", this.GetClientUrl(url)); } if (isPostBackButton && url.Any()) { var postBack = GetLinkPostBack(destinationResourceInfo); EwfPage.Instance.AddPostBack(postBack); PreRender += delegate { this.AddJavaScriptEventScript(JsWritingMethods.onclick, PostBackButton.GetPostBackScript(postBack)); }; } if (navigatesInNewWindow) { Attributes.Add("target", "_blank"); } if (popUpWindowSettings != null && url.Any()) { this.AddJavaScriptEventScript(JsWritingMethods.onclick, JsWritingMethods.GetPopUpWindowScript(url, this, popUpWindowSettings) + " return false"); } if (navigatesInOpeningWindow && (destinationResourceInfo == null || url.Any())) { var openingWindowNavigationScript = destinationResourceInfo != null ? "opener.document.location = '" + this.GetClientUrl(url) + "'; " : ""; this.AddJavaScriptEventScript(JsWritingMethods.onclick, openingWindowNavigationScript + "window.close(); return false"); } CssClass = CssClass.ConcatenateWithSpace("ewfClickable"); if (destinationResourceInfo != null && destinationResourceInfo.AlternativeMode is NewContentResourceMode) { CssClass = CssClass.ConcatenateWithSpace(CssElementCreator.NewContentClass); } ActionControlStyle.SetUpControl(this, url, width, height, setWidth); if (destinationResourceInfo != null && destinationResourceInfo.AlternativeMode is DisabledResourceMode) { var message = (destinationResourceInfo.AlternativeMode as DisabledResourceMode).Message; new ToolTip(EnterpriseWebFramework.Controls.ToolTip.GetToolTipTextControl(message.Any() ? message : Translation.ThePageYouRequestedIsDisabled), this); } else if (toolTip != null || toolTipControl != null) { new ToolTip(toolTipControl ?? EnterpriseWebFramework.Controls.ToolTip.GetToolTipTextControl(toolTip), this); } }
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 && (!isTextarea || autoPostBack || (autoCompleteService != null && autoCompleteOption != AutoCompleteOption.NoPostBack))) { EwfPage.Instance.AddPostBack(postBack); } if (!isTextarea) { 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); } } 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}; }}".FormatWith( textBox.ClientID, PostBackButton.GetPostBackScript(postBack)); 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 FormControl.FormValue { get { return(formValue); } }