Button.OnClientClick Propriété

Définition

Obtient ou définit le script côté client qui s'exécute lorsque l'événement Button d'un contrôle Click est déclenché.

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

Valeur de propriété

Script côté client qui s'exécute lorsque l'événement Button d'un contrôle Click est déclenché.

Attributs

Exemples

Un projet de site Web Visual Studio avec du code source est disponible pour accompagner cette rubrique : Télécharger.

L’exemple de code suivant montre comment utiliser la OnClientClick propriété pour spécifier un script côté client supplémentaire qui s’exécute lorsque l’utilisateur clique sur un Button contrôle.

<%@ 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 Button1_Click (object sender, EventArgs e)
  {
    Label1.Text = "Thank you for visiting our site.";

  }
  
</script>
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="head1" runat="server">
    <title>Button.OnClientClick Example</title>
</head>
<body>
  <form id="form1" runat="server">
    
    <h3>Button.OnClientClick Example</h3> 
     
      
      <h4>Click to navigate to Microsoft.com:</h4>     
              
      <asp:button id="Button1"
       usesubmitbehavior="true"
       text="Open Web site"
       onclientclick="Navigate()"
       runat="server" onclick="Button1_Click" />
       
       <p></p>
      <asp:label id="Label1"
        runat="server">
      </asp:label>

    </form>
    
    <script type="text/javascript">
      function Navigate()
      {
        javascript:window.open("http://www.microsoft.com");
      }    
      
    </script>
</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 Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs)
    Label1.Text = "Thank you for visiting our site."
  End Sub
  
</script>
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="head1" runat="server">
    <title>Button.OnClientClick Example</title>
</head>
<body>
  <form id="form1" runat="server">
    
    <h3>Button.OnClientClick Example</h3> 
     
      
      <h4>Click to navigate to Microsoft.com:</h4>     
              
      <asp:button id="Button1"
       usesubmitbehavior="true"
       text="Open Web site"
       onclientclick="Navigate()"
       runat="server" onclick="Button1_Click" />
       
       <p></p>
      <asp:label id="Label1"
        runat="server">
      </asp:label>

    </form>
    
    <script type="text/javascript">
      function Navigate()
      {
        javascript:window.open("http://www.microsoft.com");
      }    
      
    </script>
</body>
</html>

Remarques

Utilisez la OnClientClick propriété pour spécifier un script côté client supplémentaire qui s’exécute lorsque l’événement d’un ButtonClick contrôle est déclenché. Le script que vous spécifiez pour cette propriété est affiché dans l’attribut Button du OnClick contrôle en plus du script prédéfini côté client du contrôle.

Cette propriété ne peut pas être définie par les thèmes ou les thèmes de feuille de style. Pour plus d’informations, consultez ThemeableAttribute et ASP.NET Thèmes et apparences.

S’applique à

Voir aussi