日期:2014-05-18 浏览次数:20505 次
public class MyPage : System.Web.UI.Page { /// <summary> /// 调用自己自定义的HtmlTextWriter来渲染页面 /// </summary> /// <param name="writer"></param> protected override void Render(HtmlTextWriter writer) { if (writer is System.Web.UI.Html32TextWriter) { writer = new FormFixerHtml32TextWriter(writer.InnerWriter); } else { writer = new FormFixerHtmlTextWriter(writer.InnerWriter); } base.Render(writer); } } /// <summary> /// 自定义HtmlTextWriter /// </summary> internal class FormFixerHtml32TextWriter : System.Web.UI.Html32TextWriter { private string _url; // 假的URL internal FormFixerHtml32TextWriter(TextWriter writer) : base(writer) { _url = "www.baidu.com"; } public override void WriteAttribute(string name, string value, bool encode) { if (_url != null && string.Compare(name, "action", true) == 0) { value = _url; } base.WriteAttribute(name, value, encode); } } /// <summary> /// 自定义HtmlTextWriter /// </summary> internal class FormFixerHtmlTextWriter : System.Web.UI.HtmlTextWriter { private string _url; internal FormFixerHtmlTextWriter(TextWriter writer) : base(writer) { _url ="www.baidu.com"; } public override void WriteAttribute(string name, string value, bool encode) { if (_url != null && string.Compare(name, "action", true) == 0) { value = _url; } base.WriteAttribute(name, value, encode); } }