Latest web development tutorials

ASP.NET Web Forms

All server controls must appear in the <form> tag, <form> tag must contain the runat = "server" attribute.


ASP.NET Web Forms

All server controls must appear in the <form> tag, <form> tag must contain the runat = "server" attribute. runat = "server" attribute indicates that the form must be processed on the server. It also shows that the controls contained within it can be accessed by the server script:

<form runat="server">

...HTML + server controls

</form>

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

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

If you are in a contained with no name, method, action, or id attribute of the form .aspx page, choose to view the source code, you'll see ASP.NET add these attributes to the form, as shown below:

<form name="_ctl0" method="post" action="page.aspx" id="_ctl0">

...some code

</form>


Submit form

Form is usually submitted by clicking a button. Format ASP.NET Button server control is as follows:

<asp:Button id="id" text="label" OnClick="sub" runat="server" />

id attribute for the button defines a unique name, text attributes assigned a label for the button. onClick event handler specifies to execute a named subroutine.

In the following example, we declare a Button control in an .aspx file. Click the button to run the subroutine change the text on the button:

Examples