Button.UseSubmitBehavior Proprietà

Definizione

Ottiene o imposta un valore che indica se il controllo Button utilizza il meccanismo di invio del browser client o il meccanismo di postback di ASP.NET.

public:
 virtual property bool UseSubmitBehavior { bool get(); void set(bool value); };
[System.Web.UI.Themeable(false)]
public virtual bool UseSubmitBehavior { get; set; }
[<System.Web.UI.Themeable(false)>]
member this.UseSubmitBehavior : bool with get, set
Public Overridable Property UseSubmitBehavior As Boolean

Valore della proprietà

true se il controllo utilizza il meccanismo di invio del browser client, altrimenti false. Il valore predefinito è true.

Attributi

Esempio

Nell'esempio di codice seguente viene illustrato come utilizzare la UseSubmitBehavior proprietà per specificare il meccanismo di invio utilizzato da un Button controllo quando esegue il postback al server. La UseSubmitBehavior proprietà è impostata su false, causando l'uso del meccanismo di postback del pulsante ASP.NET. Se si visualizza il codice sorgente per la pagina di cui è stato eseguito il rendering usando il comando Visualizza origine del browser, si noterà che lo script sul lato client è stato aggiunto dal framework di pagina ASP.NET per pubblicare il modulo nel server.

<%@ page language="C#" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">
  
  void SubmitBtn_Click(object sender, EventArgs e)
  {
    Message.Text = "Hello World!";    
  }

</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
<head id="head1" runat="server">
  <title>Button.UseSubmitBehavior Example</title>
</head>
<body>
  <form id="form1" runat="server">

    <h3>Button.UseSubmitBehavior Example</h3> 

    Click the Submit button.
     
    <br /><br /> 

    <!--The value of the UseSubmitBehavior property
    is false. Therefore the button uses the ASP.NET 
    postback mechanism.-->
    <asp:button id="Button1"
      text="Submit"
      onclick="SubmitBtn_Click" 
      usesubmitbehavior="false"
      runat="server"/>       

    <br /><br /> 

    <asp:label id="Message" 
      runat="server"/>

  </form>
</body>
</html>
<%@ page language="VB" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">
    
  Sub SubmitBtn_Click(ByVal sender As Object, ByVal e As EventArgs)
    
    Message.Text = "Hello World!"
    
  End Sub

  </script>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
  <title>Button.UseSubmitBehavior Example</title>
</head>
<body>
  <form id="form1" runat="server">

    <h3>Button.UseSubmitBehavior Example</h3> 

    Click the Submit button.
      
    <br /><br /> 

    <!--The value of the UseSubmitBehavior property
    is false. Therefore the button uses the ASP.NET 
    postback mechanism.-->
    <asp:button id="Button1"
      text="Submit"
      onclick="SubmitBtn_Click" 
      usesubmitbehavior="false"
      runat="server"/>       

    <br /><br /> 

    <asp:label id="Message" 
      runat="server"/>

  </form>
</body>
</html>

Commenti

Utilizzare la UseSubmitBehavior proprietà per specificare se un Button controllo utilizza il meccanismo di invio del browser client o il meccanismo di postback ASP.NET. Per impostazione predefinita, il valore di questa proprietà è true, causando l'uso Button del meccanismo di invio del browser. Se si specifica false, il framework di pagina ASP.NET aggiunge script lato client alla pagina per pubblicare il modulo nel server.

Quando la UseSubmitBehavior proprietà è false, gli sviluppatori di controlli possono usare il GetPostBackEventReference metodo per restituire l'evento di postback client per .Button La stringa restituita dal GetPostBackEventReference metodo contiene il testo della chiamata di funzione sul lato client e può essere inserita in un gestore eventi lato client.

Questa proprietà non può essere impostata da temi oppure temi di fogli di stile. Per altre informazioni, vedere ThemeableAttribute e ASP.NET Temi e interfacce.

Si applica a

Vedi anche