【问题标题】:How to generate Form's OnSubmit attribute with HtmlTextWriter如何使用 HtmlTextWriter 生成 Form 的 OnSubmit 属性
【发布时间】:2018-04-18 06:38:22
【问题描述】:

我需要的 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的定义,我能通过吗?

【问题讨论】:

    标签: c# html htmltextwriter


    【解决方案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()");
    }
    

    【讨论】:

      猜你喜欢
      • 2011-04-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-11-16
      • 2021-01-19
      • 2021-03-02
      • 2013-12-05
      相关资源
      最近更新 更多