HtmlForm.Method 属性
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
获取或设置一个值,该值指示浏览器将窗体数据发送到服务器进行处理的方式。
public:
property System::String ^ Method { System::String ^ get(); void set(System::String ^ value); };
public string Method { get; set; }
member this.Method : string with get, set
Public Property Method As String
属性值
字符串,它指示浏览器向服务器发送窗体数据的方式。 默认值是 POST
。
示例
下面的代码示例演示如何使用 Method 属性来指定将表单数据发回服务器。
<%@ Page Language="C#" AutoEventWireup="True" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">
protected void AddButton_Click(Object sender, EventArgs e)
{
int Answer;
// Calculate and display the result.
Answer = Convert.ToInt32(Value1.Value) + Convert.ToInt32(Value2.Value);
AnswerMessage.InnerHtml = Answer.ToString();
}
</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
<title>HtmlForm Example</title>
</head>
<body>
<form method="Post"
enctype="application/x-www-form-urlencoded"
runat="server" id="myform">
<h3> HtmlForm Example </h3>
<table>
<tr>
<td colspan="5">
Enter integer values into the text boxes. <br />
Click the Add button to add the two values. <br />
Click the Reset button to reset the text boxes.
</td>
</tr>
<tr>
<td colspan="5">
</td>
</tr>
<tr align="center">
<td>
<input id="Value1"
type="Text"
size="2"
maxlength="3"
value="1"
runat="server"/>
</td>
<td>
+
</td>
<td>
<input id="Value2"
type="Text"
size="2"
maxlength="3"
value="1"
runat="server"/>
</td>
<td>
=
</td>
<td>
<span id="AnswerMessage"
runat="server"/>
</td>
</tr>
<tr>
<td colspan="2">
<asp:RequiredFieldValidator
ID="Value1RequiredValidator"
ControlToValidate="Value1"
ErrorMessage="Please enter a value.<br />"
Display="Dynamic"
runat="server"/>
<asp:CompareValidator
ID="Value1MinCompareValidator"
ControlToValidate="Value1"
Operator="LessThan"
Type="Integer"
ValueToCompare="100"
ErrorMessage="Please enter an integer less than 100.<br />"
Display="Dynamic"
runat="server"/>
<asp:CompareValidator
ID="Value1MaxCompareValidator"
ControlToValidate="Value1"
Operator="GreaterThan"
Type="Integer"
ValueToCompare="0"
ErrorMessage="Please enter an integer greater than 0.<br />"
Display="Dynamic"
runat="server"/>
</td>
<td colspan="2">
<asp:RequiredFieldValidator
ID="Value2RequiredValidator"
ControlToValidate="Value2"
ErrorMessage="Please enter a value.<br />"
Display="Dynamic"
runat="server"/>
<asp:CompareValidator
ID="Value2MinCompareValidator"
ControlToValidate="Value2"
Operator="LessThan"
Type="Integer"
ValueToCompare="100"
ErrorMessage="Please enter an integer less than 100.<br />"
Display="Dynamic"
runat="server"/>
<asp:CompareValidator
ID="Value2MaxCompareValidator"
ControlToValidate="Value2"
Operator="GreaterThan"
Type="Integer"
ValueToCompare="0"
ErrorMessage="Please enter an integer greater than 0.<br />"
Display="Dynamic"
runat="server"/>
</td>
<td>
</td>
</tr>
<tr align="center">
<td colspan="4">
<input type="Submit"
name="AddButton"
value="Add"
onserverclick="AddButton_Click"
runat="server"/>
<input type="Reset"
name="AddButton"
value="Reset"
runat="server"/>
</td>
<td>
</td>
</tr>
</table>
</form>
</body>
</html>
<%@ Page Language="VB" AutoEventWireup="True" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">
Protected Sub AddButton_Click(ByVal sender As Object, ByVal e As EventArgs)
Dim Answer As Integer
' Calculate and display the result.
Answer = Convert.ToInt32(Value1.Value) + Convert.ToInt32(Value2.Value)
AnswerMessage.InnerHtml = Answer.ToString()
End Sub
</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
<title>HtmlForm Example</title>
</head>
<body>
<form method="Post"
enctype="application/x-www-form-urlencoded"
runat="server" id="myform">
<h3> HtmlForm Example </h3>
<table>
<tr>
<td colspan="5">
Enter integer values into the text boxes. <br />
Click the Add button to add the two values. <br />
Click the Reset button to reset the text boxes.
</td>
</tr>
<tr>
<td colspan="5">
</td>
</tr>
<tr align="center">
<td>
<input id="Value1"
type="Text"
size="2"
maxlength="3"
value="1"
runat="server"/>
</td>
<td>
+
</td>
<td>
<input id="Value2"
type="Text"
size="2"
maxlength="3"
value="1"
runat="server"/>
</td>
<td>
=
</td>
<td>
<span id="AnswerMessage"
runat="server"/>
</td>
</tr>
<tr>
<td colspan="2">
<asp:RequiredFieldValidator
ID="Value1RequiredValidator"
ControlToValidate="Value1"
ErrorMessage="Please enter a value.<br />"
Display="Dynamic"
runat="server"/>
<asp:CompareValidator
ID="Value1MinCompareValidator"
ControlToValidate="Value1"
Operator="LessThan"
Type="Integer"
ValueToCompare="100"
ErrorMessage="Please enter an integer less than 100.<br />"
Display="Dynamic"
runat="server"/>
<asp:CompareValidator
ID="Value1MaxCompareValidator"
ControlToValidate="Value1"
Operator="GreaterThan"
Type="Integer"
ValueToCompare="0"
ErrorMessage="Please enter an integer greater than 0.<br />"
Display="Dynamic"
runat="server"/>
</td>
<td colspan="2">
<asp:RequiredFieldValidator
ID="Value2RequiredValidator"
ControlToValidate="Value2"
ErrorMessage="Please enter a value.<br />"
Display="Dynamic"
runat="server"/>
<asp:CompareValidator
ID="Value2MinCompareValidator"
ControlToValidate="Value2"
Operator="LessThan"
Type="Integer"
ValueToCompare="100"
ErrorMessage="Please enter an integer less than 100.<br />"
Display="Dynamic"
runat="server"/>
<asp:CompareValidator
ID="Value2MaxCompareValidator"
ControlToValidate="Value2"
Operator="GreaterThan"
Type="Integer"
ValueToCompare="0"
ErrorMessage="Please enter an integer greater than 0.<br />"
Display="Dynamic"
runat="server"/>
</td>
<td>
</td>
</tr>
<tr align="center">
<td colspan="4">
<input type="Submit"
name="AddButton"
value="Add"
onserverclick="AddButton_Click"
runat="server"/>
<input type="Reset"
name="AddButton"
value="Reset"
runat="server"/>
</td>
<td>
</td>
</tr>
</table>
</form>
</body>
</html>
注解
使用此属性可指定浏览器如何将表单数据发送到服务器进行处理。 所有浏览器 GET
支持的两种常见方法是和 POST
。
注意
可以重写此属性的默认值,并使用 GET
方法而不是 POST
此方法。 但是,由于GET
请求在可以包含的数据量方面受到限制,因此在某些情况下,使用GET
该方法可能会导致 ASP.NET 页面框架提供的回发和状态管理功能失败。