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

时间:2017-11-06 06:43:03

标签: c# html 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 Enum没有 OnSubmit 的定义,我会通过它吗?

1 个答案:

答案 0 :(得分:1)

我们看到HtmlTextWriter的班级具有AddAttribute

的覆盖功能
  

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

所以解决方案就像:

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