protected override void AddAttributesToRender(IHtmlWriter writer, IDotvvmRequestContext context) { if ((HasBinding(TextProperty) || !string.IsNullOrEmpty(Text)) && !HasOnlyWhiteSpaceContent()) { throw new DotvvmControlException(this, "The <dot:LinkButton> control cannot have both inner content and the Text property set!"); } writer.AddAttribute("href", "javascript:;"); var textbinding = GetValueBinding(TextProperty); if (textbinding != null) { writer.AddKnockoutDataBind("text", textbinding.GetKnockoutBindingExpression(this)); } base.AddAttributesToRender(writer, context); var clickBinding = GetCommandBinding(ClickProperty); if (clickBinding != null) { writer.AddAttribute("onclick", KnockoutHelper.GenerateClientPostBackScript(nameof(Click), clickBinding, this), true, ";"); } }
/// <summary> /// Adds all attributes that should be added to the control begin tag. /// </summary> protected override void AddAttributesToRender(IHtmlWriter writer, RenderContext context) { writer.AddKnockoutDataBind("enable", this, EnabledProperty, () => { if (!Enabled) { writer.AddAttribute("disabled", "disabled"); } }); writer.AddKnockoutDataBind("options", this, DataSourceProperty, renderEvenInServerRenderingMode: true); if (!string.IsNullOrEmpty(DisplayMember)) { writer.AddKnockoutDataBind("optionsText", "function (i) { return ko.unwrap(i)[" + KnockoutHelper.MakeStringLiteral(DisplayMember) + "]; }"); } if (!string.IsNullOrEmpty(ValueMember)) { writer.AddKnockoutDataBind("optionsValue", "function (i) { return ko.unwrap(i)[" + KnockoutHelper.MakeStringLiteral(ValueMember) + "]; }"); } // changed event var selectionChangedBinding = GetCommandBinding(SelectionChangedProperty); if (selectionChangedBinding != null) { writer.AddAttribute("onchange", KnockoutHelper.GenerateClientPostBackScript(nameof(SelectionChanged), selectionChangedBinding, context, this, isOnChange: true, useWindowSetTimeout: true)); } // selected value writer.AddKnockoutDataBind("value", this, SelectedValueProperty, renderEvenInServerRenderingMode: true); base.AddAttributesToRender(writer, context); }
protected override void AddAttributesToRender(IHtmlWriter writer, IDotvvmRequestContext context) { base.AddAttributesToRender(writer, context); var expression = KnockoutHelper.GetValidationTargetExpression(this); if (expression == null) { return; } var group = new KnockoutBindingGroup(); { group.Add("target", expression); group.Add("includeErrorsFromChildren", IncludeErrorsFromChildren.ToString().ToLower()); group.Add("includeErrorsFromTarget", IncludeErrorsFromTarget.ToString().ToLower()); group.Add("hideWhenValid", HideWhenValid.ToString().ToLower()); } writer.AddKnockoutDataBind("dotvvm-validationSummary", group); if (HideWhenValid) { writer.AddStyleAttribute("display", "none"); } }
public static void RenderChangedEvent(IHtmlWriter writer, SelectorBase selector) { var selectionChangedBinding = selector.GetCommandBinding(SelectorBase.SelectionChangedProperty); if (selectionChangedBinding != null) { writer.AddAttribute("onchange", KnockoutHelper.GenerateClientPostBackScript(nameof(SelectorBase.SelectionChanged), selectionChangedBinding, selector, isOnChange: true, useWindowSetTimeout: true), true, ";"); } }
protected virtual void RenderCheckedValueAttribute(IHtmlWriter writer) { writer.AddKnockoutDataBind("checkedValue", this, CheckedValueProperty, () => { var checkedValue = (CheckedValue ?? string.Empty).ToString(); if (!string.IsNullOrEmpty(checkedValue)) { writer.AddKnockoutDataBind("checkedValue", KnockoutHelper.MakeStringLiteral(checkedValue)); } }); }
/// <summary> /// Renders the children. /// </summary> protected override void RenderControl(IHtmlWriter writer, RenderContext context) { // label var textBinding = GetValueBinding(TextProperty); var labelRequired = textBinding != null || !string.IsNullOrEmpty(Text) || !HasOnlyWhiteSpaceContent(); if (labelRequired) { writer.RenderBeginTag("label"); } // prepare changed event attribute var changedBinding = GetCommandBinding(ChangedProperty); if (changedBinding != null) { writer.AddAttribute("onclick", KnockoutHelper.GenerateClientPostBackScript(nameof(Changed), changedBinding, context, this, true, true, isOnChange: true)); } // handle enabled attribute writer.AddKnockoutDataBind("enable", this, EnabledProperty, () => { if (!Enabled) { writer.AddAttribute("disabled", "disabled"); } }); // add ID AddAttributesToRender(writer, context); // render the radio button RenderInputTag(writer); // render the label if (labelRequired) { if (textBinding != null) { writer.AddKnockoutDataBind("text", textBinding); writer.RenderBeginTag("span"); writer.RenderEndTag(); } else if (!string.IsNullOrEmpty(Text)) { writer.WriteText(Text); } else if (!HasOnlyWhiteSpaceContent()) { RenderChildren(writer, context); } writer.RenderEndTag(); } }
/// <summary> /// Adds all attributes that should be added to the control begin tag. /// </summary> protected override void AddAttributesToRender(IHtmlWriter writer, IDotvvmRequestContext context) { var expression = KnockoutHelper.GetValidationTargetExpression(this); if (expression != null) { writer.AddKnockoutDataBind("foreach", "dotvvm.validation.getValidationErrors(" + expression + ", " + IncludeErrorsFromChildren.ToString().ToLower() + ")"); } base.AddAttributesToRender(writer, context); }
protected override void AddAttributesToRender(IHtmlWriter writer, RenderContext context) { if (!RenderOnServer) { if (!string.IsNullOrWhiteSpace(EmptyItemText)) { writer.AddKnockoutDataBind("optionsCaption", KnockoutHelper.MakeStringLiteral(EmptyItemText)); } } base.AddAttributesToRender(writer, context); }
private void AddChangedPropertyToRender(IHtmlWriter writer, IDotvvmRequestContext context) { // prepare changed event attribute var changedBinding = GetCommandBinding(ChangedProperty); base.AddAttributesToRender(writer, context); if (changedBinding != null) { writer.AddAttribute("onchange", KnockoutHelper.GenerateClientPostBackScript(nameof(Changed), changedBinding, this, useWindowSetTimeout: true, isOnChange: true), true, ";"); } }
protected virtual void RenderCheckedItemsProperty(IHtmlWriter writer) { RenderCheckedItemsBinding(writer); writer.AddKnockoutDataBind("checkedArrayContainsObservables", "true"); writer.AddKnockoutDataBind("dotvvm-checkbox-updateAfterPostback", "true"); RenderDotvvmCheckedPointerBinding(writer); writer.AddKnockoutDataBind("checkedValue", this, CheckedValueProperty, () => { var checkedValue = (CheckedValue ?? string.Empty).ToString(); if (!string.IsNullOrEmpty(checkedValue)) { writer.AddKnockoutDataBind("checkedValue", KnockoutHelper.MakeStringLiteral(checkedValue)); } }); }
protected override void AddAttributesToRender(IHtmlWriter writer, IDotvvmRequestContext context) { writer.AddKnockoutDataBind("with", this, UploadedFilesProperty, () => { throw new DotvvmControlException(this, "The UploadedFiles property of the FileUpload control must be bound!"); }); writer.AddAttribute("class", "dotvvm-upload", true); var uploadCompletedBinding = GetCommandBinding(UploadCompletedProperty); if (uploadCompletedBinding != null) { writer.AddAttribute("data-dotvvm-upload-completed", KnockoutHelper.GenerateClientPostBackScript(nameof(UploadCompleted), uploadCompletedBinding, this, useWindowSetTimeout: true, returnValue: null)); } base.AddAttributesToRender(writer, context); }
protected virtual void RenderCheckedItemsProperty(IHtmlWriter writer) { var checkedItemsBinding = GetValueBinding(CheckedItemsProperty); writer.AddKnockoutDataBind("checked", checkedItemsBinding); writer.AddKnockoutDataBind("checkedArrayContainsObservables", "true"); writer.AddKnockoutDataBind("checkedValue", this, CheckedValueProperty, () => { var checkedValue = (CheckedValue ?? string.Empty).ToString(); if (!string.IsNullOrEmpty(checkedValue)) { writer.AddKnockoutDataBind("checkedValue", KnockoutHelper.MakeStringLiteral(checkedValue)); } }); }
/// <summary> /// Adds all attributes that should be added to the control begin tag. /// </summary> protected override void AddAttributesToRender(IHtmlWriter writer, IDotvvmRequestContext context) { if ((HasBinding(TextProperty) || !string.IsNullOrEmpty(Text)) && !HasOnlyWhiteSpaceContent()) { throw new DotvvmControlException(this, "Text property and inner content of the <dot:Button> control cannot be set at the same time!"); } if (ButtonTagName == ButtonTagName.button) { TagName = "button"; } writer.AddAttribute("type", IsSubmitButton ? "submit" : "button"); writer.AddKnockoutDataBind(ButtonTagName == ButtonTagName.input ? "value" : "text", this, TextProperty, () => { if (!HasOnlyWhiteSpaceContent()) { if (ButtonTagName == ButtonTagName.input) { // if there is only a text content, extract it into the Text property; if there is HTML, we don't support it string textContent; if (!TryGetTextContent(out textContent)) { throw new DotvvmControlException(this, "The <dot:Button> control cannot have inner HTML connect unless the 'ButtonTagName' property is set to 'button'!"); } Text = textContent; } } if (ButtonTagName == ButtonTagName.input) { writer.AddAttribute("value", Text); } }); base.AddAttributesToRender(writer, context); var clickBinding = GetCommandBinding(ClickProperty); if (clickBinding != null) { writer.AddAttribute("onclick", KnockoutHelper.GenerateClientPostBackScript(nameof(Click), clickBinding, this), true, ";"); } }
private static void AddValidatedValue(IHtmlWriter writer, IDotvvmRequestContext context, DotvvmProperty prop, DotvvmControl control) { writer.AddKnockoutDataBind("dotvvmValidation", control, ValueProperty, renderEvenInServerRenderingMode: true); // render options var bindingGroup = new KnockoutBindingGroup(); foreach (var property in ValidationOptionProperties) { var javascriptName = KnockoutHelper.ConvertToCamelCase(property.Name); var optionValue = control.GetValue(property); if (!object.Equals(optionValue, property.DefaultValue)) { bindingGroup.Add(javascriptName, JsonConvert.SerializeObject(optionValue, DefaultViewModelSerializer.CreateDefaultSettings())); } } writer.AddKnockoutDataBind("dotvvmValidationOptions", bindingGroup); }
protected virtual void AddAttributesToInput(IHtmlWriter writer) { // prepare changed event attribute var changedBinding = GetCommandBinding(ChangedProperty); if (changedBinding != null) { writer.AddAttribute("onclick", KnockoutHelper.GenerateClientPostBackScript(nameof(Changed), changedBinding, this, useWindowSetTimeout: true, returnValue: true, isOnChange: true)); } // handle enabled attribute writer.AddKnockoutDataBind("enable", this, EnabledProperty, () => { if (!Enabled) { writer.AddAttribute("disabled", "disabled"); } }); }
/// <summary> /// Adds all attributes that should be added to the control begin tag. /// </summary> protected override void AddAttributesToRender(IHtmlWriter writer, RenderContext context) { if ((HasBinding(TextProperty) || !string.IsNullOrEmpty(Text)) && !HasOnlyWhiteSpaceContent()) { throw new DotvvmControlException(this, "The <dot:LinkButton> control cannot have both inner content and the Text property set!"); } writer.AddAttribute("href", "#"); var clickBinding = GetCommandBinding(ClickProperty); if (clickBinding != null) { writer.AddAttribute("onclick", KnockoutHelper.GenerateClientPostBackScript(nameof(Click), clickBinding, context, this)); } writer.AddKnockoutDataBind("text", this, TextProperty, () => { shouldRenderText = true; }); base.AddAttributesToRender(writer, context); }
/// <summary> /// Adds all attributes that should be added to the control begin tag. /// </summary> protected override void AddAttributesToRender(IHtmlWriter writer, IDotvvmRequestContext context) { writer.AddKnockoutDataBind("enable", this, EnabledProperty, () => { if (!Enabled) { writer.AddAttribute("disabled", "disabled"); } }); AddValueAndFormatBindingAttribute(writer, context); if (Type == TextBoxType.MultiLine) { TagName = "textarea"; } else if (Type == TextBoxType.Normal) { TagName = "input"; // do not overwrite type attribute if (!Attributes.ContainsKey("type")) { writer.AddAttribute("type", "text"); } } else { string type = null; switch (Type) { case TextBoxType.Password: type = "password"; break; case TextBoxType.Telephone: type = "tel"; break; case TextBoxType.Url: type = "url"; break; case TextBoxType.Email: type = "email"; break; case TextBoxType.Date: type = "date"; break; case TextBoxType.Time: type = "time"; break; case TextBoxType.Color: type = "color"; break; case TextBoxType.Search: type = "search"; break; case TextBoxType.Number: type = "number"; break; default: throw new NotSupportedException($"TextBox Type '{ Type }' not supported"); } writer.AddAttribute("type", type); TagName = "input"; } // prepare changed event attribute var changedBinding = GetCommandBinding(ChangedProperty); if (changedBinding != null) { writer.AddAttribute("onchange", KnockoutHelper.GenerateClientPostBackScript(nameof(Changed), changedBinding, this, useWindowSetTimeout: true, isOnChange: true)); } base.AddAttributesToRender(writer, context); }
public static void RenderOptionsProperties(IHtmlWriter writer, SelectorBase selector) { writer.AddKnockoutDataBind("options", selector, ItemsControl.DataSourceProperty, renderEvenInServerRenderingMode: true); if (selector.ItemTextBinding != null) { writer.AddKnockoutDataBind("optionsText", selector.ItemTextBinding.GetProperty <SelectorItemBindingProperty>().Expression, selector); } else if (!String.IsNullOrEmpty(selector.DisplayMember)) { writer.AddKnockoutDataBind("optionsText", "function (i) { return ko.unwrap(i)[" + KnockoutHelper.MakeStringLiteral(selector.DisplayMember) + "]; }"); } if (selector.ItemValueBinding != null) { writer.AddKnockoutDataBind("optionsValue", selector.ItemValueBinding.GetProperty <SelectorItemBindingProperty>().Expression, selector); } else if (!String.IsNullOrEmpty(selector.ValueMember)) { writer.AddKnockoutDataBind("optionsValue", "function (i) { return ko.unwrap(i)[" + KnockoutHelper.MakeStringLiteral(selector.ValueMember) + "]; }"); } }