当前位置: 首页 > 网络学院 > 服务端脚本教程 > ASP.NET > ASP.NET Web 表单

ASP.NET
ASP.NET 2.0 - Navigation 导航
C#中new和override区别
ASP.NET中 Bin,App_Browser,App_code,App_Data,App_Theme 等文件

ASP.NET Web 表单


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-03-01   浏览: 949 ::
收藏到网摘: n/a

All server controls must appear within a <form> tag, and the <form> tag must contain the runat="server" attribute.
所有服务器控件必须出现在<form>标签当中,而且<form>标签必须要包含runat='server'属性


ASP.NET Web Forms
ASP.NET Web 表单

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:
runat="server" 属性象征着这个表单应该在服务器上进行处理。这还象征着附在表单里的控件可以被服务端脚本进行访问:

<form runat="server">
...HTML + server controls
...HTML + 服务器控件
</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.
注意:表单总是会提交到自身页面上。如果你指定了action属性,它会被忽略。如果你没指定method属性,它会默认的设置为method='post'。如果你没有指定name和id属性,ASP.net会自动的给予分配。

Note: An .aspx page can only contain ONE <form runat="server"> control!
注意:一个aspx页面只可以含有一个<form runat="server">控件!

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:
如果你选择查看一个没有指定name,method , action或id属性表单的.aspx页面,你将看到ASP.NET会给表单填加上去。看上去就像这样:

<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.NET中Button服务器控件遵循以下格式:

<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.
id属性定义了一个唯一的名称来对应的按钮,并且text属性会分配给按钮一个标签。onClick事件处理器指定一个被命名的子程序来执行

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:
在下面的举例里将在一个.aspx文件中声明一个Button控件。按钮按下后将执行子程序来改变按钮的文字:

Example(查看举例)

评论 (1) 1 All

登陆 | 还没注册?