Export (0) Print
Expand All

HtmlForm.Target Property

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

Namespace:  System.Web.UI.HtmlControls
Assembly:  System.Web (in System.Web.dll)

public string Target { get; set; }
<asp:HtmlForm Target="String" />

Property Value

Type: System.String
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.

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.

NoteNote

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.

NoteNote

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.

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">
               &nbsp;
            </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>
               &nbsp;
             </td>
         </tr>
         <tr align="center">
            <td colspan="4">
               <input type="Submit"
                      name="AddButton"
                      value="Add"
                      onserverclick="AddButton_Click"
                      runat="server"/>

               &nbsp;&nbsp;&nbsp;

               <input type="Reset"
                      name="AddButton"
                      value="Reset"
                      runat="server"/>

            </td>
            <td>
               &nbsp;
            </td>
         </tr>
      </table>

   </form>
</body>

</html>

.NET Framework

Supported in: 4.5.2, 4.5.1, 4.5, 4, 3.5, 3.0, 2.0, 1.1, 1.0

Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

Show:
© 2014 Microsoft