ASP.NET Tutoria...login
ASP.NET Tutorial
author:php.cn  update time:2022-04-11 14:18:18

Web Forms


ASP.NET Web Forms - HTML Form


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


ASP.NET Web Form

All server controls must appear in the <form> tag, and the <form> 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:

<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 metion attribute, it will default to method="post". Also, if you do not specify the name and id attributes, they are automatically assigned by ASP.NET.

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

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

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

...some code

</form>


Submit form

Forms are 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, 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 the .aspx file. Clicking a button runs a subroutine that changes the text on the button:

Example


php.cn