HtmlForm.Target Proprietà

Definizione

Ottiene o imposta il frame o la finestra in cui visualizzare i risultati delle informazioni inviate al 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

Valore della proprietà

Frame o finestra del browser in cui vengono visualizzati i risultati delle informazioni inviate al server. Il valore predefinito è una stringa vuota ("") che aggiorna la finestra o il frame attivi.

Esempio

Nell'esempio di codice seguente viene illustrato come utilizzare la Target proprietà per specificare una nuova finestra senza frame per visualizzare i risultati delle informazioni pubblicate nel 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>

Commenti

Utilizzare la Target proprietà per specificare la finestra o il frame di destinazione che visualizza i risultati delle informazioni inviate al server. Il reindirizzamento dei risultati delle informazioni inviate al server è un'attività avanzata. Non è consigliabile usare questa proprietà semplicemente per eseguire il postback.

Nota

Il rendering della Target proprietà viene eseguito come target attributo. L'attributo target sugli form elementi non è consentito in XHTML 1.1. Pertanto, se il markup sottoposto a rendering deve essere conforme agli standard XHTML o deve essere conforme agli standard di accessibilità, non impostare la Target proprietà . Per altre informazioni, vedere Standard XHTML in Visual Studio e ASP.NET e accessibilità in Visual Studio e ASP.NET.

Il Target valore deve iniziare con una lettera nell'intervallo da A a Z (senza distinzione tra maiuscole e minuscole), ad eccezione dei valori speciali seguenti, che iniziano con un carattere di sottolineatura.

Valore di destinazione Descrizione
_blank Visualizza il contenuto in una nuova finestra senza frame.
_parent Visualizza il contenuto nell'elemento padre immediato del set di frame.
_search Visualizza il contenuto nel riquadro di ricerca.
_self Consente di visualizzare il contenuto nel frame attivo.
_top Visualizza il contenuto in tutta la finestra senza frame.

Nota

Controllare nella documentazione relativa al browser se è supportato il valore _search. Ad esempio, Microsoft Internet Explorer 5.0 e versioni successive supportano il valore di destinazione _search.

Si applica a

Vedi anche