0

如何防止name="..."属性呈现为 HtmlInputButton 的一部分?

代码:

 var button = new System.Web.UI.HtmlControls.HtmlInputButton();
 button.Value = "abc";

呈现的 HTML:

<input name="ctl00$AppName_Content$ctl01" type="button" value="abc"/>
4

1 回答 1

0

您可以覆盖 render 方法并阻止添加属性。

private class RemoveNamesHtmlTextWriter : HtmlTextWriter
{    
    public override void WriteAttribute(string name, string value, bool fEncode) 
    { 
        if (name.Equals("name", StringComparison.OrdinalIgnoreCase)) return;
            return; 

        base.WriteAttribute(name, value, fEncode); 
    }
}

protected override void Render(HtmlTextWriter writer)
{
    var RemoveNamesWriter = new RemoveNamesHtmlTextWriter(writer);

    base.Render(RemoveNamesWriter);
}

您可以在此处参考以获取更多信息:如何删除“名称”属性

于 2013-06-12T05:55:16.880 回答