zoukankan      html  css  js  c++  java
  • HtmlTextWriter类的学习

    为了学习方便,将在网上找的资料先保存起来,然后慢慢看,如有侵权的话,请您来信告知,我会在第一时删除:

    在创建自定义控件的时候,如果控件继承自Control类,我们会发现有个Render方法,Render方法输出的是HtmlTextWriter类型的变量。

    HtmlTextWriter继承于System.IO.TextWriter,

    使用HtmlTextWriter的枚举有很多好处:比如可以获得IntelliSense支持,重要的是.net会对枚举的值自动进行类型检查

    HtmlTextWriter的各种方法的参数取值包括以下三种类型的枚举:

    1HtmlTextWriterTag

         指定可传递到 HtmlTextWriter Html32TextWriter 对象输出流的 HTML 标记。

           该枚举使输出流可以在响应 Web 请求时连同 HTML 服务器控件一起编写 HTML 标记。

           成员如下

    成员名称

    说明

    A

    指定 HTML a 元素。

    Acronym

    指定 HTML acronym 元素。

    Address

    指定 HTML address 元素。

    Area

    指定 HTML area 元素。

    B

    指定 HTML b 元素。

    Base

    指定 HTML base 元素。

    Basefont

    指定 HTML basefont 元素。

    Bdo

    指定 HTML bdo 元素。

    Bgsound

    指定 HTML bgsound 元素。

    Big

    指定 HTML big 元素。

    Blockquote

    指定 HTML blockquote 元素。

    Body

    指定 HTML body 元素。

    Br

    指定 HTML br 元素。

    Button

    指定 HTML button 元素。

    Caption

    指定 HTML caption 元素。

    Center

    指定 HTML center 元素。

    Cite

    指定 HTML cite 元素。

    Code

    指定 HTML code 元素。

    Col

    指定 HTML col 元素。

    Colgroup

    指定 HTML colgroup 元素。

    Dd

    指定 HTML dd 元素。

    Del

    指定 HTML cel 元素。

    Dfn

    指定 HTML dfn 元素。

    Dir

    指定 HTML dir 元素。

    Div

    指定 HTML div 元素。

    Dl

    指定 HTML dl 元素。

    Dt

    指定 HTML dt 元素。

    Em

    指定 HTML em 元素。

    Embed

    指定 HTML embed 元素。

    Fieldset

    指定 HTML fieldset 元素。

    Font

    指定 HTML font 元素。

    Form

    指定 HTML form 元素。

    Frame

    指定 HTML frame 元素。

    Frameset

    指定 HTML frameset 元素。

    H1

    指定 HTML H1 元素。

    H2

    指定 HTML H2 元素。

    H3

    指定 HTML H3 元素。

    H4

    指定 HTML H4 元素。

    H5

    指定 HTML H5 元素。

    H6

    指定 HTML H6 元素。

    Head

    指定 HTML head 元素。

    Hr

    指定 HTML hr 元素。

    Html

    指定 HTML html 元素。

    I

    指定 HTML i 元素。

    Iframe

    指定 HTML iframe 元素。

    Img

    指定 HTML img 元素。

    Input

    指定 HTML input 元素。

    Ins

    指定 HTML ins 元素。

    Isindex

    指定 HTML isindex 元素。

    Kbd

    指定 HTML kbd 元素。

    Label

    指定 HTML label 元素。

    Legend

    指定 HTML legend 元素。

    Li

    指定 HTML li 元素。

    Link

    指定 HTML link 元素。

    Map

    指定 HTML map 元素。

    Marquee

    指定 HTML marquee 元素。

    Menu

    指定 HTML menu 元素。

    Meta

    指定 HTML meta 元素。

    Nobr

    指定 HTML nobr 元素。

    Noframes

    指定 HTML noframes 元素。

    Noscript

    指定 HTML noscript 元素。

    Object

    指定 HTML object 元素。

    Ol

    指定 HTML ol 元素。

    Option

    指定 HTML option 元素。

    P

    指定 HTML p 元素。

    Param

    指定 HTML param 元素。

    Pre

    指定 HTML pre 元素。

    Q

    指定 HTML q 元素。

    Rt

    指定 DHTML rt 元素,后者指定 ruby 元素的文本。

    Ruby

    指定 DHTML ruby 元素。

    S

    指定 HTML s 元素。

    Samp

    指定 HTML samp 元素。

    Script

    指定 HTML script 元素。

    Select

    指定 HTML select 元素。

    Small

    指定 HTML small 元素。

    Span

    指定 HTML span 元素。

    Strike

    指定 HTML strike 元素。

    Strong

    指定 HTML strong 元素。

    Style

    指定 HTML style 元素。

    Sub

    指定 HTML sub 元素。

    Sup

    指定 HTML sup 元素。

    Table

    指定 HTML table 元素。

    Tbody

    指定 HTML tbody 元素。

    Td

    指定 HTML td 元素。

    Textarea

    指定 HTML textarea 元素。

    Tfoot

    指定 HTML tfoot 元素。

    Th

    指定 HTML th 元素。

    Thead

    指定 HTML thead 元素。

    Title

    指定 HTML title 元素。

    Tr

    指定 HTML tr 元素。

    Tt

    指定 HTML tt 元素。

    U

    指定 HTML u 元素。

    Ul

    指定 HTML ul 元素。

    Unknown

    不识别作为 HTML 标记传递的 String

    Var

    指定 HTML var 元素。

    Wbr

    指定 HTML wbr 元素。

    Xml

    指定 HTML xml 元素。

    代码示例:

    ----------――――――――――――――――――――――――――――――――

    [C#]

    // Control HTML encoding of attributes.

    // Simple known values do not need encoding.

    writer.AddAttribute(HtmlTextWriterAttribute.Alt, "Encoding, \"Required\"", true);

    writer.AddAttribute("myattribute", "No "encodig " required", false);

    writer.RenderBeginTag(HtmlTextWriterTag.Img);

    writer.RenderEndTag();

    writer.WriteLine();

    ----------――――――――――――――――――――――――――――――――

    2HtmlTextWriterAttribute

         指定 HTML 属性,在处理 Web 请求时,HtmlTextWriter Html32TextWriter 对象将该属性写入 HTML 元素的开始标记。

    此枚举经常与 HtmlTextWriter 类的下列方法联合使用:AddAttributeGetAttributeNameIsAttributeDefined RenderBeginTag

    成员如下:

    成员名称

    说明

    Accesskey

    指定将 HTML acesskey 属性写入标记。

    Align

    指定将 HTML align 属性写入标记。

    Alt

    指定将 HTML alt 属性写入标记。

    Background

    指定将 HTML background 属性写入标记。

    Bgcolor

    指定将 HTML bgcolor 属性写入标记。

    Border

    指定将 HTML border 属性写入标记。

    Bordercolor

    指定将 HTML bordercolor 属性写入标记。

    Cellpadding

    指定将 HTML cellpadding 属性写入标记。

    Cellspacing

    指定将 HTML cellspacing 属性写入标记。

    Checked

    指定将 HTML checked 属性写入标记。

    Class

    指定将 HTML class 属性写入标记。

    Cols

    指定将 HTML cols 属性写入标记。

    Colspan

    指定将 HTML colspan 属性写入标记。

    Disabled

    指定将 HTML disabled 属性写入标记。

    For

    指定将 HTML for 属性写入标记。

    Height

    指定将 HTML height 属性写入标记。

    Href

    指定将 HTML href 属性写入标记。

    Id

    指定将 HTML id 属性写入标记。

    Maxlength

    指定将 HTML maxlength 属性写入标记。

    Multiple

    指定将 HTML multiple 属性写入标记。

    Name

    指定将 HTML name 属性写入标记。

    Nowrap

    指定将 HTML nowrap 属性写入标记。

    Onchange

    指定将 HTML onchange 属性写入标记。

    Onclick

    指定将 HTML onclick 属性写入标记。

    ReadOnly

    指定将 HTML readonly 属性写入标记。

    Rows

    指定将 HTML rows 属性写入标记。

    Rowspan

    指定将 HTML rowspan 属性写入标记。

    Rules

    指定将 HTML rules 属性写入标记。

    Selected

    指定将 HTML selected 属性写入标记。

    Size

    指定将 HTML size 属性写入标记。

    Src

    指定将 HTML src 属性写入标记。

    Style

    指定将 HTML style 属性写入标记。

    Tabindex

    指定将 HTML tabindex 属性写入标记。

    Target

    指定将 HTML target 属性写入标记。

    Title

    指定将 HTML title 属性写入标记。

    Type

    指定将 HTML type 属性写入标记。

    Valign

    指定将 HTML valign 属性写入标记。

    Value

    指定将 HTML value 属性写入标记。

    Width

    指定将 HTML width 属性写入标记。

    Wrap

    指定将 HTML wrap 属性写入标记。

    代码示例:

    [C#]

    writer.AddAttribute(HtmlTextWriterAttribute.Onclick, "alert('Hello');");

    3HtmlTextWriterStyle

    指定可用于 HtmlTextWriter Html32TextWriter 对象输出流的 HTML 样式。

    HtmlTextWriter Html32TextWriter 对象使用这些枚举值将 HTML 字符串注册为正确的 HTML 样式。

    成员如下:

    成员名称

    说明

    BackgroundColor

    指定 HTML backgroundcolor 样式。

    BackgroundImage

    指定 HTML backgroundimage 样式。

    BorderCollapse

    指定 HTML bordercollapse 样式。

    BorderColor

    指定 HTML bordercolor 样式。

    BorderStyle

    指定 HTML borderstyle 样式。

    BorderWidth

    指定 HTML borderwidth 样式。

    Color

    指定 HTML color 样式。

    FontFamily

    指定 HTML fontfamily 样式。

    FontSize

    指定 HTML fontsize 样式。

    FontStyle

    指定 HTML fontstyle 样式。

    FontWeight

    指定 HTML fontweight 样式。

    Height

    指定 HTML height 样式。

    TextDecoration

    指定 HTML textdecoration 样式。

    Width

    指定 HTML width 样式。

    代码示例:

    -----――――――――――――――――――――――――――――――――

    [C#]

    writer.AddStyleAttribute(HtmlTextWriterStyle.Color, "Red");

    ------―――――――――――――――――――――――――――――――

  • 相关阅读:
    java 执行 jar 包中的 main 方法
    seven habits of highly effective people 高效能人士的七个习惯
    支付系统对账算法优化方案 转
    iso 培训笔记
    Android日常开发总结的技术经验60条 转
    ANDROID学习之路 转
    Businessworks的设计思想
    JVM内存模型和性能优化 转
    高可用架构设计与实践
    大规模分布式存储实战
  • 原文地址:https://www.cnblogs.com/edrp/p/651409.html
Copyright © 2011-2022 走看看