本文共 1694 字,大约阅读时间需要 5 分钟。
using System;
using System.Web.UI;using System.Web.UI.WebControls;using System.ComponentModel;namespace blackflash
{ /// <summary> /// Anchor 的摘要说明。 /// </summary> [DefaultProperty("Text"), ToolboxData("<{0}:Anchor runat=server></{0}:Anchor>")] public class Anchor : Control, IAttributeAccessor { [Bindable(true), Category("Appearance"), DefaultValue("")] public String Title { get { return (string)ViewState["Title"]; } set { ViewState["Title"] = value; } } public String Target { get { return (String)ViewState["Target"]; } set { ViewState["Target"] = value; } } public String Text { get { return (String)ViewState["Text"]; } set { ViewState["Text"] = value; } } public String Href { get { return (String)ViewState["Href"]; } set { ViewState["Href"] = value; } } public String Style { get { return (String)ViewState["Style"]; } set { ViewState["Style"] = value; } } public String Class { get { return (String)ViewState["Class"]; } set { ViewState["Class"] = value; } } public void SetAttribute(String name, String value1) { ViewState[name] = value1; } public String GetAttribute(String name) { return (String)ViewState[name]; }/// <summary>
/// 将此控件呈现给指定的输出参数。 /// </summary> /// <param name="output"> 要写出到的 HTML 编写器 </param> protected override void Render(HtmlTextWriter output) { output.Write("<a"); if (this.Href !=null) { output.Write(" href='"+this.Href+"'"); } if (this.Style !=null) { output.Write(" style='"+this.Style+"'"); } if (this.Title !=null) { output.Write(" title='"+this.Title+"'"); } if (this.Target !=null) { output.Write(" target='"+this.Target+"'"); } if (this.Class !=null) { output.Write(" class='"+this.Class+"'"); } output.Write(">" + this.Text + " </a>"); } }}转载地址:http://fbptd.baihongyu.com/