HtmlForm.Target Property

Definition

Gets or sets the frame or window in which to render the results of information that is posted to the server.

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

Property Value

The browser window or frame that displays the results of the information posted to the server. The default is an empty string (""), which refreshes the window or frame with focus.

Examples

The following code example demonstrates how to use the Target property to specify a new, unframed window to display the results of the information posted back to the server.

<%@ 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>

Remarks

Use the Target property to specify the target window or frame that displays the results of the information that is posted to the server. Redirecting the results of the information posted to the server is an advanced task. Using this property simply to post back is not recommended.

Note

The Target property renders as a target attribute. The target attribute on form elements is not allowed in XHTML 1.1. Therefore, if the rendered markup must conform to XHTML standards or must conform to accessibility standards, do not set the Target property. For more information, see XHTML Standards in Visual Studio and ASP.NET and Accessibility in Visual Studio and ASP.NET.

The Target value must begin with a letter in the range of A to Z (case-insensitive), except for the following special values, which begin with an underscore.

Target value Description
_blank Renders the content in a new window without frames.
_parent Renders the content in the immediate frameset parent.
_search Renders the content in the search pane.
_self Renders the content in the frame with focus.
_top Renders the content in the full window without frames.

Note

Check your browser documentation to determine if the _search value is supported. For example, Microsoft Internet Explorer 5.0 and later support the _search target value.

Applies to

See also