ASP.NET Web Forms
All server controls must appear within a <form> tag, and the <form> tag must contain the runat="server" attribute.
ASP.NET Web Forms
All server controls must appear within a <form> tag, and the <form> tag must contain the runat="server" attribute. The runat="server" attribute indicates that the form should be processed//执行 on the server. It also indicates that the enclosed//补附上的 controls can be accessed//访问 by server scripts:
<form runat="server"> ...HTML + server controls </form> |
Note: The form//窗体 is always submitted to the page itself. If you specify//指明 an action attribute//动作属性, it is ignored. If you omit//忽略 the method attribute//方法属性, it will be 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 page can only contain ONE <form runat="server"> control!
If you select view source//源码视图 in an .aspx page containing a form with no name, method, action, or id attribute specified//指定的, you will see that ASP.NET has added these attributes to the form. It looks something like this:
<form name="_ctl0" method="post" action="page.aspx" id="_ctl0"> ...some code </form> |
Submitting a Form
A form is most often submitted by clicking on a button. The Button server control//按钮服务器端控件 in ASP.NET has the following format:
<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 execute.
In the following example we declare a Button control//按钮控件 in an .aspx file. A button click runs a subroutine//子程序 which changes the text on the button:
Example:
ASPX Source:
| <script runat="server"> Sub submit(Source As Object, e As EventArgs) button1.Text="You clicked me!" End Sub </script> <html> <body> <form runat="server"> <asp:Button id="button1" Text="Click me!" runat="server" OnClick="submit" /> </form> </body> </html> |
Output Result:
a.
|
|
|
|
浙公网安备 33010602011771号