Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

ASP.NET Web Forms

ASP.NET Web Forms - HTML Forms


All server controls must appear within a

tag, and the tag must contain the runat="server" attribute.


ASP.NET Web Forms

All server controls must appear within a tag, and the tag must contain the runat="server" attribute. The runat="server" attribute indicates that the form must be processed on the server. It also indicates that the controls contained within it can be accessed by server scripts:

...HTML + server controls

**Note:** The form is always submitted to its own page. If you specify an action attribute, it is ignored. If you omit the method attribute, it is set to method="post" by default. Also, if you do not specify the name and id attributes, they are assigned automatically by ASP.NET.

**Note:** An .aspx page can only contain one

control!

If you choose to view the source code in 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:

...some code


Submitting a Form

Forms are usually submitted by clicking a button. The format of the 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 example below, we declare a button control in an .aspx file. A single mouse click runs a subroutine that changes the text on the button.

Example