如何使用 HtmlTextWriter 生成 Form 的 OnSubmit 属性

How to generate Form's OnSubmit attribute with HtmlTextWriter

我需要 Html 类似于:

<form onsubmit="return manipulateForm()">
...
</form>

我正在用

生成它
HtmlTextWriterAttribute key;
string value;

using (HtmlTextWriter writer = new HtmlTextWriter(new System.IO.StringWriter(innerBuffer)))
{
    writer.AddAttribute(key, value);
}

问题是 HtmlTextWriterAttribute 枚举没有 OnSubmit 的定义,我能顺利通过吗?

刚看到HtmlTextWriter的class有覆盖AddAttribute的功能

public virtual void AddAttribute(string name, string value);

所以解决方案如下:

using (HtmlTextWriter writer = new HtmlTextWriter(new System.IO.StringWriter(innerBuffer)))
{
    writer.AddAttribute("onsubmit", "return manipulateForm()");
}