private void AssertDropDownListSpan(XmlNode contentSpan, AutoPostBack autoPostBack) { var inputSpan = contentSpan.GetAssertedChildElement("span", 0); inputSpan.AssertChildElementCount(0); inputSpan.AssertTextNode("TextBox", 0); int hiddenFieldIndex = 1; if (Control.Enabled) { var dropDownButton = contentSpan.GetAssertedChildElement("span", 1); dropDownButton.AssertAttributeValueEquals("class", "bocAutoCompleteReferenceValueButton"); dropDownButton.AssertChildElementCount(1); var dropDownSpacer = dropDownButton.GetAssertedChildElement("img", 0); dropDownSpacer.AssertAttributeValueEquals("src", IconInfo.CreateSpacer(_resourceUrlFactory).Url); dropDownSpacer.AssertChildElementCount(0); hiddenFieldIndex++; } var hiddenField = contentSpan.GetAssertedChildElement("input", hiddenFieldIndex); hiddenField.AssertAttributeValueEquals("id", c_keyValueName); hiddenField.AssertAttributeValueEquals("name", c_keyValueName); hiddenField.AssertAttributeValueEquals("type", "hidden"); if (autoPostBack == AutoPostBack.Enabled) { hiddenField.AssertAttributeValueEquals("onchange", "PostBackEventReference"); } else { hiddenField.AssertNoAttribute("onchange"); } hiddenField.AssertChildElementCount(0); }
protected override void OnPreRender(System.EventArgs e) { base.OnPreRender(e); var scriptManager = ScriptManager.GetCurrent(Page); var asyncEnabled = scriptManager != null; if (AddJQueryReference) { IncludeJqueryScript(scriptManager, asyncEnabled); } #if DEBUG var scriptResource = checkBoxScriptResource; #else var scriptResource = checkBoxMinScriptResource; #endif if (asyncEnabled) { scriptManager.Scripts.Add(new ScriptReference(Page.ClientScript.GetWebResourceUrl(this.GetType(), scriptResource))); } else { Page.ClientScript.RegisterClientScriptInclude("dd_script", Page.ClientScript.GetWebResourceUrl(this.GetType(), scriptResource)); } var initializeScript = string.Format( initScript, ClientID, divPstfx, selectPstfx, "dd_chk_" + ClientID, UseButtons.ToString().ToLower(), AutoPostBack.ToString().ToLower(), UseSelectAllNode.ToString().ToLower()); var cssRef = string.Format("<link rel='stylesheet' type='text/css' href='{0}' />", Page.ClientScript.GetWebResourceUrl(this.GetType(), defaultCssResource)); var postbackScript = string.Format("function dd_chk_{0}(){{ {1} }}", ClientID, Page.ClientScript.GetPostBackEventReference(this, null)); if (asyncEnabled && !AreScriptsInitialized && scriptManager.IsInAsyncPostBack) { ScriptManager.RegisterStartupScript(this, GetType(), ClientID, initializeScript, true); ScriptManager.RegisterClientScriptBlock(this, GetType(), "post_" + ClientID, postbackScript, true); AreScriptsInitialized = true; } else { Page.ClientScript.RegisterStartupScript(GetType(), ClientID, initializeScript, true); Page.ClientScript.RegisterClientScriptBlock(GetType(), "post_" + ClientID, postbackScript, true); AreScriptsInitialized = true; } Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "dd_chk_styles", cssRef, false); if (Page.IsPostBack && asyncEnabled && (PropertiesAreDirty || Texts.IsDirty || Style.IsDirty)) { var script = string.Format( updateScript, ClientID, divPstfx, selectPstfx, "dd_chk_" + ClientID, UseButtons.ToString().ToLower(), AutoPostBack.ToString().ToLower(), UseSelectAllNode.ToString().ToLower()); ScriptManager.RegisterStartupScript(this, GetType(), ClientID + "_upd", script, true); } }
protected override void OnPreRender(EventArgs e) { base.OnPreRender(e); if (Visible) { AutoPostBack |= HasDependingFields; ScriptHelper.RegisterJQuery(Page); ScriptHelper.RegisterJQueryUI(Page); ScriptHelper.RegisterScriptFile(Page, "~/CMSScripts/Controls/Autocomplete.js"); // Events creation String events = String.Empty; if (!String.IsNullOrEmpty(OnBeforeClientChanged)) { events += String.Format("$cmsj('#{0}_txtAutocomplete').bind('onBeforeChange', function (e, value) {{{1}}});", ClientID, OnBeforeClientChanged); } if (!String.IsNullOrEmpty(OnAfterClientChanged)) { events += String.Format("$cmsj('#{0}_txtAutocomplete').bind('onAfterChange', function (e, value) {{{1}}});", ClientID, OnAfterClientChanged); } // Display '(none)' item if (AllowEmpty) { Items.Insert(0, new ListItem() { Value = "", Text = GetString("general.empty") }); } // Conver Items collection to JSON format StringBuilder sb = new StringBuilder(); foreach (ListItem li in Items) { sb.Append("{", CreateItemJSON("Text", li.Text, true), ",", CreateItemJSON("Value", li.Value)); foreach (String key in li.Attributes.Keys) { sb.Append(",", CreateItemJSON(key, li.Attributes[key])); } sb.Append("},"); } String strSet = "[" + sb.ToString().TrimEnd(',') + "]"; // Initial javascripts String init = String.Format(@" $cmsj(document).ready(function () {{ setUpSelector('{0}', {1},'{2}',{3}); {4} }}); ", ClientID, AutoPostBack.ToString().ToLowerCSafe(), GetString("general.nodatafound"), strSet, events); ScriptHelper.RegisterClientScriptBlock(this, typeof(String), ClientID + "InitAutocompleteDropDown", ScriptHelper.GetScript(init)); // Select first item if (String.IsNullOrEmpty(txtAutocomplete.Text) && String.IsNullOrEmpty(hdnValue.Value) && (Items.Count > 0)) { txtAutocomplete.Text = Items[0].Text; hdnValue.Value = Items[0].Value; } } }
private void AssertControl(XmlNode containerDiv, OptionMenuConfiguration optionMenuConfiguration, AutoPostBack autoPostBack) { var contentDiv = containerDiv.GetAssertedChildElement("span", 0); contentDiv.AssertAttributeValueEquals("class", "body"); AssertIcon(contentDiv, true); var contentSpan = contentDiv.GetAssertedChildElement("span", 1); switch (optionMenuConfiguration) { case OptionMenuConfiguration.NoOptionsMenu: contentSpan.AssertAttributeValueEquals("class", "content withoutOptionsMenu"); break; case OptionMenuConfiguration.SeparateOptionsMenu: contentSpan.AssertAttributeValueEquals("class", "content separateOptionsMenu"); break; case OptionMenuConfiguration.EmbeddedOptionsMenu: contentSpan.AssertAttributeValueEquals("class", "content embeddedOptionsMenu"); break; } AssertDropDownListSpan(contentSpan, autoPostBack); if (optionMenuConfiguration == OptionMenuConfiguration.SeparateOptionsMenu) { var optionsMenuDiv = contentDiv.GetAssertedChildElement("span", 2); optionsMenuDiv.AssertAttributeValueEquals("class", "optionsMenu"); optionsMenuDiv.AssertTextNode("DropDownMenu", 0); } }