如何在 C# 中将 Button 的类型设置为 "Button"(而不是默认的 "Submit")?

How can I set a Button's type to "Button" (as opposed to the default "Submit") in C#?

根据回答 here,我可以通过将其类型值设置为 "Button" 来阻止按钮提交表单,就像在 HTML:

中一样
<button type="button">Cancel changes</button>

...但是我如何在 C# 中执行此操作?我正在动态创建我的控件,就像这样(伪代码,因为我远离我的 IDE):

button btn = new Button 
             {
               CSS = "bla"
             }
btn.Type = "Button"; // <- something like this?

如果您想要 "HTML button tag"

,请使用 HtmlButton 而不是 Button
var btn = new HtmlButton();
btn.Attributes["class"] = "bla";
btn.Attributes["type"] = "button";

按钮呈现 <input type="submit" />,Button.UseSubmitBehavior 呈现 <input type="button" />

HtmlButton 将呈现 <button type="YOUR_DEFINITION"></button>