更新时间:2023-01-31 21:55:27
简短的回答是否定的,您将不得不覆盖 name 属性的呈现,以下示例来自此问题:ASP.NET:如何从服务器控件中删除名称"属性?
Short answer is no, you will have to override the rendering of the name attribute, example below from this question: ASP.NET: how to remove 'name' attribute from server controls?
public class NoNamesTextBox : TextBox
{
private class NoNamesHtmlTextWriter : HtmlTextWriter
{
public NoNamesHtmlTextWriter(TextWriter writer) : base(writer) {}
public override void WriteAttribute(string name, string value, bool fEncode)
{
if (name.Equals("name", StringComparison.OrdinalIgnoreCase)) return;
base.WriteAttribute(name, value, fEncode);
}
}
protected override void Render(HtmlTextWriter writer)
{
var noNamesWriter = new NoNamesHtmlTextWriter(writer);
base.Render(noNamesWriter);
}
}