本文整理汇总了C#中IHtmlWriter类的典型用法代码示例。如果您正苦于以下问题:C# IHtmlWriter类的具体用法?C# IHtmlWriter怎么用?C# IHtmlWriter使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
IHtmlWriter类属于命名空间,在下文中一共展示了IHtmlWriter类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: SetupDataBind
private void SetupDataBind(IHtmlWriter htmlWriter)
{
htmlWriter
.Prop("id", this.propertyName)
.Prop("name", this.propertyName)
.Prop("data-bind", "value:" + this.field.PropertyName);
}
示例2: RenderControl
protected override void RenderControl(IHtmlWriter writer, IDotvvmRequestContext context)
{
if (!RenderOnServer || GetIEnumerableFromDataSource(DataSource)?.GetEnumerator()?.MoveNext() != true)
{
base.RenderControl(writer, context);
}
}
示例3: AddAttributesToRender
/// <summary>
/// Adds all attributes that should be added to the control begin tag.
/// </summary>
protected override void AddAttributesToRender(IHtmlWriter writer, RenderContext context)
{
if (!RenderOnServer)
{
writer.AddKnockoutDataBind("options", this, DataSourceProperty, () => { });
if (!string.IsNullOrEmpty(DisplayMember))
{
writer.AddKnockoutDataBind("optionsText", KnockoutHelper.MakeStringLiteral(DisplayMember));
}
if (!string.IsNullOrEmpty(ValueMember))
{
writer.AddKnockoutDataBind("optionsValue", KnockoutHelper.MakeStringLiteral(ValueMember));
}
}
// changed event
var selectionChangedBinding = GetCommandBinding(SelectionChangedProperty);
if (selectionChangedBinding != null)
{
writer.AddAttribute("onchange", KnockoutHelper.GenerateClientPostBackScript(selectionChangedBinding, context, this));
}
// selected value
writer.AddKnockoutDataBind("value", this, SelectedValueProperty, () => { });
base.AddAttributesToRender(writer, context);
}
示例4: RenderContents
/// <summary>
/// Renders the contents inside the control begin and end tags.
/// </summary>
protected override void RenderContents(IHtmlWriter writer, RenderContext context)
{
if (RenderOnServer)
{
// render items
bool first = true;
foreach (var item in GetIEnumerableFromDataSource(DataSource))
{
var value = string.IsNullOrEmpty(ValueMember) ? item : ReflectionUtils.GetObjectProperty(item, ValueMember);
var text = string.IsNullOrEmpty(DisplayMember) ? item : ReflectionUtils.GetObjectProperty(item, DisplayMember);
if (first)
{
writer.WriteUnencodedText(Environment.NewLine);
first = false;
}
writer.WriteUnencodedText(" "); //Indent
writer.AddAttribute("value", value != null ? value.ToString() : "");
writer.RenderBeginTag("option");
writer.WriteText(text != null ? text.ToString() : "");
writer.RenderEndTag();
writer.WriteUnencodedText(Environment.NewLine);
}
}
}
示例5: RenderContents
/// <summary>
/// Renders the contents inside the control begin and end tags.
/// </summary>
protected override void RenderContents(IHtmlWriter writer, IDotvvmRequestContext context)
{
// render template
writer.AddKnockoutDataBind("text", "errorMessage");
writer.RenderBeginTag("li");
writer.RenderEndTag();
}
示例6: Render
/// <summary>
/// Renders the resource in the specified <see cref="IHtmlWriter" />.
/// </summary>
public override void Render(IHtmlWriter writer, IDotvvmRequestContext context)
{
writer.AddAttribute("href", GetUrl());
writer.AddAttribute("rel", "stylesheet");
writer.AddAttribute("type", "text/css");
writer.RenderSelfClosingTag("link");
}
示例7: Render
/// <summary>
/// Renders the resource in the specified <see cref="IHtmlWriter" />.
/// </summary>
public override void Render(IHtmlWriter writer, string friendlyName = null)
{
writer.AddAttribute("type", "text/javascript");
writer.RenderBeginTag("script");
writer.WriteUnencodedText(Code);
writer.RenderEndTag();
}
示例8: Render
/// <summary>
/// Renders the resource in the specified <see cref="IHtmlWriter" />.
/// </summary>
public override void Render(IHtmlWriter writer, IDotvvmRequestContext context)
{
if (CdnUrl != null)
{
writer.AddAttribute("src", CdnUrl);
writer.AddAttribute("type", "text/javascript");
writer.RenderBeginTag("script");
writer.RenderEndTag();
if (Url != null && GlobalObjectName != null)
{
writer.RenderBeginTag("script");
var url = context.TranslateVirtualPath(GetUrl());
writer.WriteUnencodedText(string.Format(CdnFallbackScript, GlobalObjectName, url));
writer.RenderEndTag();
}
}
else if (Url != null)
{
writer.AddAttribute("src", GetUrl());
writer.AddAttribute("type", "text/javascript");
writer.RenderBeginTag("script");
writer.RenderEndTag();
}
}
示例9: RenderInputTag
/// <summary>
/// Renders the input tag.
/// </summary>
protected override void RenderInputTag(IHtmlWriter writer)
{
var checkedBinding = GetValueBinding(CheckedProperty);
var checkedItemsBinding = GetValueBinding(CheckedItemsProperty);
if (checkedBinding != null && checkedItemsBinding == null)
{
// boolean mode
writer.AddKnockoutDataBind("checked", this, CheckedProperty, () => { });
writer.AddKnockoutDataBind("checkedValue", "true");
}
else if (checkedBinding == null && checkedItemsBinding != null)
{
// collection mode
writer.AddKnockoutDataBind("checked", this, CheckedItemsProperty, () => { });
writer.AddKnockoutDataBind("checkedValue", this, CheckedValueProperty, () =>
{
var checkedValue = (CheckedValue ?? string.Empty).ToString();
if (!string.IsNullOrEmpty(checkedValue))
{
writer.AddKnockoutDataBind("checkedValue", KnockoutHelper.MakeStringLiteral(checkedValue));
}
});
}
else
{
throw new Exception("Either the Checked or the CheckedItems property of a CheckBox must be set.");
}
// render the input tag
writer.AddAttribute("type", "checkbox");
writer.RenderSelfClosingTag("input");
}
示例10: Render
/// <summary>
/// Renders the resource in the specified <see cref="IHtmlWriter" />.
/// </summary>
public override void Render(IHtmlWriter writer, string friendlyName = null)
{
writer.AddAttribute("href", GetUrl(friendlyName));
writer.AddAttribute("rel", "stylesheet");
writer.AddAttribute("type", "text/css");
writer.RenderSelfClosingTag("link");
}
示例11: RenderControl
protected override void RenderControl(IHtmlWriter writer)
{
// begin
if (Mode == TextMode.MultiLine)
{
writer.RenderBeginTag("textarea");
}
else
{
writer.RenderBeginTag("input");
writer.AddAttribute("type", Mode.ToString().ToLower());
}
// content
var expr = KnockoutBindingHelper.GetBindingExpressionOrNull(TextProperty, this);
if (!KnockoutBindingHelper.IsKnockoutBinding(expr))
{
if (Mode == TextMode.MultiLine)
{
writer.WriteText(Text, true);
}
else
{
writer.AddAttribute("value", Text);
}
}
else
{
writer.AddBindingAttribute("value", KnockoutBindingHelper.TranslateToKnockoutProperty(this, TextProperty, expr));
}
// end
writer.RenderEndTag();
}
示例12: AddAttributesToRender
protected override void AddAttributesToRender(IHtmlWriter writer, RenderContext context)
{
writer.AddAttribute("class", "form-horizontal");
writer.AddAttribute("role", "form");
base.AddAttributesToRender(writer, context);
}
示例13: AddAttributesToRender
/// <summary>
/// Adds all attributes that should be added to the control begin tag.
/// </summary>
protected override void AddAttributesToRender(IHtmlWriter writer, IDotvvmRequestContext context)
{
object id;
if (!IsPropertySet(ClientIDProperty))
{
SetValueRaw(ClientIDProperty, id = CreateClientId());
}
else
{
id = GetValueRaw(ClientIDProperty);
}
if (id != null) Attributes["id"] = id;
CheckInnerTextUsage();
// verify that the properties are used only where they should
if (!RendersHtmlTag)
{
EnsureNoAttributesSet();
}
else
{
var attrBindingGroup = new KnockoutBindingGroup();
// render hard-coded HTML attributes
foreach (var attribute in Attributes)
{
if (attribute.Value is IValueBinding)
{
var binding = attribute.Value as IValueBinding;
attrBindingGroup.Add(attribute.Key, binding.GetKnockoutBindingExpression());
if (!RenderOnServer)
continue;
}
AddHtmlAttribute(writer, attribute.Key, attribute.Value);
}
if (!attrBindingGroup.IsEmpty)
{
writer.AddKnockoutDataBind("attr", attrBindingGroup);
}
// handle Visible property
AddVisibleAttributeOrBinding(writer);
// handle Text property
writer.AddKnockoutDataBind("text", this, InnerTextProperty, () =>
{
// inner Text is rendered as attribute only if contains binding
// otherwise it is rendered directly as encoded content
if (!string.IsNullOrWhiteSpace(InnerText))
{
Children.Clear();
Children.Add(new Literal(InnerText));
}
});
}
base.AddAttributesToRender(writer, context);
}
示例14: RenderControl
protected override void RenderControl(IHtmlWriter writer)
{
writer.RenderBeginTag(Element);
if (htmlAttributesStorage != null)
htmlAttributesStorage.Render(writer);
base.RenderControl(writer);
writer.RenderEndTag(true);
}
示例15: RenderChangedEvent
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));
}
}