本文整理汇总了C#中System.Web.UI.XhtmlTextWriter类的典型用法代码示例。如果您正苦于以下问题:C# XhtmlTextWriter类的具体用法?C# XhtmlTextWriter怎么用?C# XhtmlTextWriter使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
XhtmlTextWriter类属于System.Web.UI命名空间,在下文中一共展示了XhtmlTextWriter类的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。
示例1: CustomXhtmlTextWriter
//引入命名空间
using System;
using System.IO;
using System.Web;
using System.Security.Permissions;
using System.Web.UI;
using System.Web.UI.Adapters;
using System.Web.UI.WebControls.Adapters;
namespace Samples.AspNet.CS
{
// Create a class that inherits from XhtmlTextWriter.
[AspNetHostingPermission(SecurityAction.Demand,
Level=AspNetHostingPermissionLevel.Minimal)]
[AspNetHostingPermission(SecurityAction.InheritanceDemand,
Level=AspNetHostingPermissionLevel.Minimal)]
public class CustomXhtmlTextWriter : XhtmlTextWriter
{
// Create two constructors, following
// the pattern for implementing a
// TextWriter constructor.
public CustomXhtmlTextWriter(TextWriter writer) :
this(writer, DefaultTabString)
{
}
public CustomXhtmlTextWriter(TextWriter writer, string tabString) :
base(writer, tabString)
{
}
// Override the OnAttributeRender method to
// allow this text writer to render only eight-point
// text size.
protected override bool OnAttributeRender(string name,
string value,
HtmlTextWriterAttribute key)
{
if (key == HtmlTextWriterAttribute.Size)
{
if (String.Compare(value, "8pt") == 0)
{
return true;
}
else
{
return false;
}
}
else
{
return base.OnAttributeRender(name, value, key);
}
}
// Override the OnStyleAttributeRender
// method to prevent this text writer
// from rendering purple text.
protected override bool OnStyleAttributeRender(string name,
string value,
HtmlTextWriterStyle key)
{
if (key == HtmlTextWriterStyle.Color)
{
if (String.Compare(value, "purple") == 0)
{
return false;
}
else
{
return true;
}
}
else
{
return base.OnStyleAttributeRender(name, value, key);
}
}
// Override the BeginRender method to write a
// message and call the WriteBreak method
// before a control is rendered.
override public void BeginRender()
{
this.Write("A control is about to render.");
this.WriteBreak();
}
// Override the EndRender method to
// write a string immediately after
// a control has rendered.
override public void EndRender()
{
this.Write("A control just rendered.");
}
}
}
开发者ID:.NET开发者,项目名称:System.Web.UI,代码行数:97,代码来源:XhtmlTextWriter
示例2: return
//引入命名空间
using System;
using System.Web;
using System.Web.UI;
using System.Web.UI.Adapters;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.Adapters;
namespace AspNet.Samples
{
// Create a simple class that inherits
// from the Label class.
public class TestLabel : Label
{
private String _textValue;
// Override the Text property.
public override string Text
{
get
{
return (string)ViewState["Text"];
}
set
{
ViewState["Text"] = value;
}
}
}
public class XhtmlTestLabelAdapter : WebControlAdapter
{
// Create a control property that accesses the
// methods and properties of the control.
protected TestLabel Control
{
get
{
return (TestLabel)base.Control;
}
}
protected override void Render(HtmlTextWriter writer)
{
// Create an instance of the XhtmlTextWriter class,
// named w, and cast the HtmlTextWriter passed
// in the writer parameter to w.
XhtmlTextWriter w = new XhtmlTextWriter(writer);
// Create a string variable, named value, to hold
// the control's Text property value.
String value = Control.Text;
// Create a Boolean variable, named attTest,
// to test whether the Style attribute is
// valid in the page that the control is
// rendered to.
Boolean attTest = w.IsValidFormAttribute("style");
// Check whether attTest is true or false.
// If true, a style is applied to the XHTML
// content. If false, no style is applied.
if (attTest)
w.EnterStyle(Control.ControlStyle);
// Write the Text property value of the control,
// a <br> element, and a string. Consider encoding the value using WriteEncodedText.
w.Write(value);
w.WriteBreak();
w.Write("This control conditionally rendered its styles for XHTML.");
// Check whether attTest is true or false.
// If true, the XHTML style is closed.
// If false, nothing is rendered.
if (attTest)
w.ExitStyle(Control.ControlStyle);
}
}
}
开发者ID:.NET开发者,项目名称:System.Web.UI,代码行数:78,代码来源:XhtmlTextWriter
注:本文中的System.Web.UI.XhtmlTextWriter类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论