當前位置: 首頁>>代碼示例>>C#>>正文


C# XhtmlTextWriter類代碼示例

本文整理匯總了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;未經允許,請勿轉載。