... I'm generating it with HtmlTextWriterAttribute key; stri" /> ... I'm generating it with HtmlTextWriterAttribute key; stri" /> ... I'm generating it with HtmlTextWriterAttribute key; stri"/>

How to generate Form's OnSubmit attribute with HtmlTextWriter

91 views Asked by At

I need the Html will be something like:

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

I'm generating it with

HtmlTextWriterAttribute key;
string value;

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

The problem is that the HtmlTextWriterAttribute Enum does not have a definition for OnSubmit, hot do i get passed it?

1

There are 1 answers

0
Shahar Shokrani On BEST ANSWER

Just saw that the class of HtmlTextWriter has override function for AddAttribute

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

So the solution will be like:

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