public virtual void When_multiple_Add_calls_use_same_key_it_throws() { var attributes = new HtmlAttributes(); attributes.Add("class", "one"); Assert.Throws <ArgumentException>(() => attributes.Add("class", "two")); }
/// ----------------------------------------------------------------------------- /// <summary> /// Look for skin level doctype configuration file, and inject the value into the top of default.aspx /// when no configuration if found, the doctype for versions prior to 4.4 is used to maintain backwards compatibility with existing skins. /// Adds xmlns and lang parameters when appropiate. /// </summary> /// <param name="Skin">The currently loading skin</param> /// <remarks></remarks> /// <history> /// [cathal] 11/29/2006 Created /// [cniknet] 05/20/2009 Refactored to use HtmlAttributes collection /// </history> /// ----------------------------------------------------------------------------- private void SetSkinDoctype() { string strLang = CultureInfo.CurrentCulture.ToString(); string strDocType = PortalSettings.ActiveTab.SkinDoctype; if (strDocType.Contains("XHTML 1.0")) { //XHTML 1.0 HtmlAttributes.Add("xml:lang", strLang); HtmlAttributes.Add("lang", strLang); HtmlAttributes.Add("xmlns", "http://www.w3.org/1999/xhtml"); } else if (strDocType.Contains("XHTML 1.1")) { //XHTML 1.1 HtmlAttributes.Add("xml:lang", strLang); HtmlAttributes.Add("xmlns", "http://www.w3.org/1999/xhtml"); } else { //other HtmlAttributes.Add("lang", strLang); } //Find the placeholder control and render the doctype skinDocType.Text = PortalSettings.ActiveTab.SkinDoctype; attributeList.Text = HtmlAttributeList; }
public static MvcHtmlString TextAreaForMiniUI <T, F>(this HtmlHelper <T> helper, Expression <Func <T, F> > expression, object htmlAttributes = null) where T : class { var metadata = ModelMetadata.FromLambdaExpression(expression, new ViewDataDictionary <T>()); if (metadata == null) { return(MvcHtmlString.Empty); } TagBuilder tagBuilder = new TagBuilder("input"); IDictionary <string, object> HtmlAttributes = HtmlHelper.AnonymousObjectToHtmlAttributes(htmlAttributes); if (HtmlAttributes == null) { HtmlAttributes = new Dictionary <string, object>(); } HtmlAttributes.Add("class", "mini-textbox"); HtmlAttributes.Add("id", metadata.PropertyName); HtmlAttributes.Add("name", metadata.PropertyName); if (metadata.IsRequired) { HtmlAttributes.Add("required", "true"); } HtmlAttributes.Add("emptyText", metadata.Description); tagBuilder.MergeAttributes <string, object>(HtmlAttributes); return(new MvcHtmlString(tagBuilder.ToString(TagRenderMode.SelfClosing))); }
string RenderHeader() { var columns = new TagBuilder("div"); columns.MergeAttribute("property", "columns"); var indexColumn = new TagBuilder("div"); indexColumn.MergeAttribute("type", "indexcolumn"); columns.InnerHtml = columns.InnerHtml + indexColumn.ToString(); if (this._multiSelect) { var checkColumn = new TagBuilder("div"); checkColumn.MergeAttribute("type", "checkcolumn"); columns.InnerHtml = columns.InnerHtml + checkColumn.ToString(); } foreach (var item in this.Columns) { var column = new TagBuilder("div"); IDictionary <string, object> HtmlAttributes = HtmlHelper.AnonymousObjectToHtmlAttributes(item.HtmlAttributes); if (HtmlAttributes == null) { HtmlAttributes = new Dictionary <string, object>(); } HtmlAttributes.Add("field", item.DataField); HtmlAttributes.Add("allowSort", item.Sortable.ToString().ToLower()); HtmlAttributes.Add("width", string.IsNullOrEmpty(item.Width) ? "100" : item.Width); HtmlAttributes.Add("headerAlign", string.IsNullOrEmpty(item.Align) ? "center" : item.Align); column.MergeAttributes <string, object>(HtmlAttributes); column.SetInnerText(item.Title); columns.InnerHtml = columns.InnerHtml + column.ToString(); } return(columns.ToString()); }
/// <summary> /// Called by the framework when the component needs to be rendered as HTML. /// </summary> /// <param name="model">The model being rendered by the component.</param> /// <returns>The component rendered as HTML.</returns> public async Task <string> RenderAsync(long?model) { string val = model != null?model.ToString() : ""; HtmlAttributes.Add("class", "yt_text20"); HtmlAttributes.Add("maxlength", "30"); return(await TextEditComponent.RenderTextAsync(this, val, "yt_longvalue")); }
public virtual void Classes_are_overwritten_during_set_operations() { var attributes = new HtmlAttributes(); attributes.Add("class", "one"); attributes["class"] = "two"; attributes["class"].Should().Be("two"); }
public virtual void Dictionary_Add_adds_items_to_dictionary() { var attributes = new HtmlAttributes(); attributes.Add("foo", "bar"); var value = attributes["foo"].ToString(); value.Should().Be("bar"); }
public virtual void Classes_are_overwritten_during_dynamic_set_operations() { dynamic attributes = new HtmlAttributes(); attributes.Add("class", "one"); attributes.@class = "two"; string @class = attributes.@class; @class.Should().Be("two"); }
public FileUploader(Localizer localizer) { HtmlAttributes.AppendCssClass("fu-fileupload"); HtmlAttributes.Add("data-accept", "gif,jpeg,jpg,png"); HtmlAttributes.Add("data-show-remove-after-upload", "false"); if (localizer != null) { UploadText = localizer("Common.Fileuploader.Upload"); } }
/// <summary> /// Called by the framework when the component needs to be rendered as HTML. /// </summary> /// <param name="model">The model being rendered by the component.</param> /// <returns>The component rendered as HTML.</returns> public async Task <string> RenderAsync(string model) { HtmlAttributes.Add("class", "yt_text40"); StringLengthAttribute lenAttr = PropData.TryGetAttribute <StringLengthAttribute>(); if (lenAttr == null) { HtmlAttributes.Add("maxlength", Globals.MaxEmail.ToString()); } return(await TextEditComponent.RenderTextAsync(this, model?.ToString() ?? "", "yt_email")); }
public FileUploader(Localizer localizer) { HtmlAttributes.AppendCssClass("fileupload form-row align-items-center"); HtmlAttributes.Add("data-accept", "gif|jpe?g|png"); HtmlAttributes.Add("data-show-remove-after-upload", "false"); IconCssClass = "fa fa-upload"; ButtonStyle = ButtonStyle.Secondary; if (localizer != null) { CancelText = localizer("Common.Fileuploader.Cancel"); RemoveText = localizer("Common.Remove"); UploadText = localizer("Common.Fileuploader.Upload"); } }
public SelectBuilder <TModel, TProperty> Select2(string placeholder = null, bool allowClear = false) { CssClasses.Add("select2"); if (!string.IsNullOrEmpty(placeholder)) { HtmlAttributes.Add("data-placeholder", placeholder); } if (allowClear) { HtmlAttributes.Add("data-allowClear", "true"); } return(this); }
protected override string Render() { // Data var ajaxOptions = new AjaxOptions { HttpMethod = (IsPost ? "POST" : "GET"), InsertionMode = InsertionMode.Replace, UpdateTargetId = UpdateTargetId, LoadingElementId = LoadingElementId, OnSuccess = "new function(){" + OnSuccessFun?.Replace("\"", "\'") + "}" }; RouteValues = HtmlHelperExtension.AddRouteValue(RouteValues, new { area = _areaName }); // Style HtmlAttributes = HtmlHelperExtension.AddCssClass(HtmlAttributes, CssHelper <ButtonControlAjax> .ConvertToCss(BackgroundColor)); HtmlAttributes = HtmlHelperExtension.AddCssClass(HtmlAttributes, CssHelper <ButtonControlAjax> .ConvertToCss(Size)); // Id if (Id != null) { HtmlAttributes.Add("id", Id); } string innerHtmlOrText = string.Empty; if (!string.IsNullOrEmpty(MaterialIcon)) { innerHtmlOrText = string.Format(base.RenderMaterialIcon(MaterialIcon)); } else { innerHtmlOrText = Text ?? string.Empty; } // Reference:http://stackoverflow.com/questions/12008899/create-ajax-actionlink-with-html-elements-in-the-link-text var replacedText = Guid.NewGuid().ToString(); var actionLink = _ajaxHelper.ActionLink(replacedText, _actionName, _controllerName, RouteValues, ajaxOptions, HtmlAttributes); return(actionLink.ToString().Replace(replacedText, innerHtmlOrText)); }
/// <summary> /// Merges the specified attribute to the definition of this instance /// </summary> /// <param name="key">Attribute name</param> /// <param name="value">Attribute value</param> protected void MergeHtmlAttribute(string key, string value) { if (HtmlAttributes != null) { if (HtmlAttributes.ContainsKey(key)) { HtmlAttributes[key] = value; } else { HtmlAttributes.Add(key, value); } } else { HtmlAttributes = new Dictionary <string, object> { { key, value } }; } }
protected override string Render() { // Create tag builder TagBuilder builder; if (IsLinkBtn) { builder = new TagBuilder("a"); IsSubmitBtn = false; } else { builder = new TagBuilder("button"); } // Id builder.GenerateId(Id); // Text builder.SetInnerText(Text); // IsSubmit HtmlAttributes.Add("type", IsSubmitBtn?"submit":"button"); // Material Icon if (!string.IsNullOrEmpty(MaterialIcon)) { builder.InnerHtml = RenderMaterialIcon(MaterialIcon); } // Merge Attributes builder.MergeAttributes(HtmlAttributes); // Style: SetColor & SetSize builder.AddCssClass(CssHelper <ButtonControl> .ControlTypeAbbr); builder.AddCssClass(CssHelper <ButtonControl> .ConvertToCss(BackgroundColor)); builder.AddCssClass(CssHelper <ButtonControl> .ConvertToCss(Size)); return(builder.ToString()); }
public string ToHtmlString() { var gridview = new TagBuilder("div"); gridview.GenerateId(this._gridname); gridview.AddCssClass("mini-datagrid"); IDictionary <string, object> HtmlAttributes = HtmlHelper.AnonymousObjectToHtmlAttributes(this._htmlAttributes); if (HtmlAttributes == null) { HtmlAttributes = new Dictionary <string, object>(); } HtmlAttributes.Add("style", "width: 100%; height: 100%;"); HtmlAttributes.Add("url", this._url); HtmlAttributes.Add("showColumnsMenu", "true"); HtmlAttributes.Add("multiSelect", this._multiSelect.ToString().ToLower()); gridview.MergeAttributes <string, object>(HtmlAttributes); string temp = RenderHeader(); gridview.InnerHtml = temp; return(gridview.ToString()); }
protected override void addMainTagAttributes() { DefaultId = _name.Replace(".", "_"); HtmlAttributes.Add("name", _name); HtmlAttributes.Add("class", "KYT_selectboxPicker selectboxPicker"); }
internal void For(string name) { HtmlAttributes.Add("for", name); }
/// <summary> /// Called by the framework when the component needs to be rendered as HTML. /// </summary> /// <param name="model">The model being rendered by the component.</param> /// <returns>The component rendered as HTML.</returns> public async Task <string> RenderAsync(Guid?model) { HtmlAttributes.Add("class", "yt_text40"); HtmlAttributes.Add("maxlength", "40"); return(await TextEditComponent.RenderTextAsync(this, model != null?model.ToString() : "", "yt_guid")); }
/// <summary> /// Called by the framework when the component needs to be rendered as HTML. /// </summary> /// <param name="model">The model being rendered by the component.</param> /// <returns>The component rendered as HTML.</returns> public async Task <string> RenderAsync(string model) { HtmlAttributes.Add("class", "yt_urlremotepage"); HtmlAttributes.Add("maxlength", Globals.MaxUrl); return(await TextEditComponent.RenderTextAsync(this, model != null?model : "", "yt_urlremotepage")); }
public T HasAttribute(string key, string value) { HtmlAttributes.Add(key, value); return((T)this); }
/// <summary> /// Called by the framework when the component needs to be rendered as HTML. /// </summary> /// <param name="model">The model being rendered by the component.</param> /// <returns>The component rendered as HTML.</returns> public async Task <string> RenderAsync(string model) { HtmlAttributes.Add("type", "password"); HtmlAttributes.Add("autocomplete", "new-password"); return(await TextEditComponent.RenderTextAsync(this, model, "yt_password20")); }