Easy Tutorial
❮ Webpages Publish Webpages Ref Helpers ❯

ASP.NET Web Forms - HTML Forms

All server controls must be placed within a <form> tag, which must include the runat="server" attribute.


ASP.NET Web Forms

All server controls must be placed within a <form> tag, which must include the runat="server" attribute. The runat="server" attribute indicates that the form must be processed on the server. It also indicates that the controls within it can be accessed by server scripts:

Note: This form is always submitted to the same page. If you specify an action attribute, it will be ignored. If you omit the method attribute, it will default to method="post". Also, if you do not specify name and id attributes, they will be assigned automatically by ASP.NET.

Note: An .aspx page can only contain one <form runat="server"> control!

If you view the source code of an .aspx page that contains a form without name, method, action, or id attributes, you will see that ASP.NET adds these attributes to the form, as shown below:


Submitting Forms

Forms are typically submitted by clicking a button. The format of a Button server control in ASP.NET is as follows:

The id attribute defines a unique name for the button, and the text attribute assigns a label to the button. The onClick event handler specifies a named subroutine to be executed.

In the following example, we declare a button control in an .aspx file. A single mouse click can run a subroutine that changes the text on the button.

Example

❮ Webpages Publish Webpages Ref Helpers ❯