asp.net: difference between runat="server" and server controls

Dasha Salo picture Dasha Salo · May 18, 2009 · Viewed 7.3k times · Source

What is the difference in functionality between

<asp:Button id="button1" Text="Click me" runat="server" OnClick="submitEvent" />

and

<input type="button" id="button1" runat="server" value="Click me" />

Does the input with runat="server" attribute has other or limited properties and methods?

Thank you!

Answer

Guffa picture Guffa · May 18, 2009

The first one creates a System.Web.UI.WebControls.Button while the second one creates a System.Web.UI.HtmlControls.HtmlInputButton.

Both are server controls, but the controls in the WebControls namespace generally has a bit more functionality than the controls in the HtmlControls namespace. Typically they put some data in ViewState to keep track of their state, and they have server side postback events.

Each controls in the HtmlControls namespace correspond exactly to an HTML element, while the controls in the WebControls namespace may be rendered differently depending on what the browser that is requesting the page can support.