HtmlForm.Target 属性

定义

获取或设置框架或窗口以呈现发送到服务器的信息结果。

public:
 property System::String ^ Target { System::String ^ get(); void set(System::String ^ value); };
public string Target { get; set; }
member this.Target : string with get, set
Public Property Target As String

属性值

显示发送到服务器的信息结果的浏览器窗口或框架。 默认值为空字符串 (""),这会刷新具有焦点的窗口或框架。

示例

下面的代码示例演示如何使用 Target 属性指定一个新的非框架窗口,以显示发回服务器的信息的结果。

<%@ 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 Target Property Example</title>
</head>
<body>

   <form id="form1" method="Post"
         enctype="application/x-www-form-urlencoded"
            target="_blank"
         runat="server">

      <h3> HtmlForm Target Property 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 Target Property Example</title>
</head>
<body>

   <form id="form1" method="Post"
         enctype="application/x-www-form-urlencoded"
            target="_blank"
         runat="server">

      <h3> HtmlForm Target Property 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>

注解

Target使用 属性可以指定显示发布到服务器的信息的结果的目标窗口或框架。 重定向发布到服务器的信息的结果是一项高级任务。 不建议仅将此属性用于回发。

注意

属性 Target 呈现为 target 特性。 target XHTML 1.1 中不允许元素上的 form 属性。 因此,如果呈现的标记必须符合 XHTML 标准或必须符合辅助功能标准,请不要设置 Target 属性。 有关详细信息,请参阅 Visual Studio 中的 XHTML 标准以及 Visual Studio 中的 ASP.NET和辅助功能以及 ASP.NET

该值 Target 必须以 A 到 Z 范围内的字母开头, (不区分大小写) ,以下特殊值除外,它们以下划线开头。

目标值 说明
_blank 将内容呈现在一个没有框架的新窗口中。
_parent 将内容呈现在上一个框架集父级中。
_search 在搜索窗格中呈现内容。
_self 将内容呈现在含焦点的框架中。
_top 将内容呈现在没有框架的全窗口中。

注意

请查看浏览器文档,确定是否支持 _search 值。 例如,Microsoft Internet Explorer 5.0 及更高版本支持 _search 目标值。

适用于

另请参阅