All server controls must appear in the <form> label, and the <form> label must contain the runat = "server" attribute. The runat = "server" attribute indicates that the form must be processed on the server. It also indicates whether the control to be loaded can be accessed by the server script:
<form runat="server">...HTML + server controls</form>
Note: This 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 ". At the same time, if you do not specify the name and id attributes, they are automatically allocated by ASP. NET.
Note: One. aspx can only contain one <form runat = "server"> control!
If you view. source code of the aspx page, and the form contained in it does not contain the name, method, action, or id attribute, you will see ASP. NET has added these attributes to the form. Similar to this:
<form name="_ctl0" method="post" action="page.aspx" id="_ctl0">...some code</form>
Submit Form
A form is usually submitted by clicking a button. The format of the Button Server Control in ASP. NET is as follows:
<asp:Button id="id" text="label" OnClick="sub" runat="server" />
The id attribute defines a unique name for the button, while the text attribute assigns a label to the button. The onClick event handle specifies a subroutine to be executed.
In the following example, we declare a button control in A. aspx file. You can run a subroutine with one mouse click to change the text on the button.