Asp. NET Tutorial: Web Forms

Source: Internet
Author: User

All server controls must appear inside the <form> tab, and the <form> label must contain the runat= "server" attribute. runat= the "server" attribute indicates that the form must be processed at the server. It also indicates whether the mounted control can be accessed by server script:

<form runat= "Server" .... HTML + Server controls</form>

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 automatically assigned by ASP.net.

Note: an. aspx can contain only one <form runat= "server" > Control!

If you view the source code for an. aspx page that contains a form that does not have the name, method, action, or ID attribute, you will see that asp.net has added these attributes to the form. Something like this:

<form name= "_ctl0" method= "post" action= "page.aspx" id= "_ctl0" >...some code</form>
  Submitting a form

The form is usually submitted by clicking a button. The format of the Button server control in asp.net is this:

<asp:button id= "id" text= "label" onclick= "Sub" runat= "Server"/>

The ID property defines a unique name for the button, and the Text property assigns a label to the button. The OnClick event handle prescribes a subroutine to execute.

In the following example, we declare a button control in an. aspx file. You can run a subroutine one time with a mouse click to change the text on the button.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.