1

According to an answer here, I can prevent a button from submitting the form by setting its type value to "Button", like so in HTML:

<button type="button">Cancel changes</button>

...but how can I do this in C#? I am creating my controls dynamically, something like this (pseudocode, as I'm away from my IDE):

button btn = new Button 
             {
               CSS = "bla"
             }
btn.Type = "Button"; // <- something like this?
TylerH
  • 20,799
  • 66
  • 75
  • 101
B. Clay Shannon-B. Crow Raven
  • 8,547
  • 144
  • 472
  • 862

1 Answers1

3

Use HtmlButton instead of Button if you want the "HTML button tag"

var btn = new HtmlButton();
btn.Attributes["class"] = "bla";
btn.Attributes["type"] = "button";

Button renders <input type="submit" /> and Button.UseSubmitBehavior renders <input type="button" />.

HtmlButton will render <button type="YOUR_DEFINITION"></button>.

Alexandre Perez
  • 3,355
  • 3
  • 21
  • 21