Button.Click Událost

Definice

Vyvolá se při Button kliknutí na ovládací prvek.

public:
 event EventHandler ^ Click;
public:
 virtual event EventHandler ^ Click;
public event EventHandler Click;
member this.Click : EventHandler 
Public Custom Event Click As EventHandler 

Event Type

Implementuje

Příklady

Následující příklad kódu ukazuje, jak určit a kód obslužné rutiny události pro Click událost, aby se zobrazila zpráva na webové stránce při Button kliknutí na ovládací prvek.

<%@ 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 Page_Load(Object sender, EventArgs e)
    {
        // Manually register the event-handling method for
        // the Click event of the Button control.
        Button1.Click += new EventHandler(this.GreetingBtn_Click);
    }

    void GreetingBtn_Click(Object sender,
                           EventArgs e)
    {
        // When the button is clicked,
        // change the button text, and disable it.

        Button clickedButton = (Button)sender;
        clickedButton.Text = "...button clicked...";
        clickedButton.Enabled = false;
        
        // Display the greeting label text.
        GreetingLabel.Visible = true;
    }

</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>Untitled Page</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
      <h3>Simple Button Example</h3>
     
      <asp:Button id="Button1"
           Text="Click here for greeting..."
           OnClick="GreetingBtn_Click" 
           runat="server"/>
      <br />
      <br />
      <asp:Label ID="GreetingLabel" runat="server" 
                 Visible="false" Text="Hello World!" />
    </div>
    </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 GreetingBtn_Click(ByVal sender As Object, _
                          ByVal e As EventArgs)
   
        ' When the button is clicked,
        ' change the button text, and disable it.
        
        Dim clickedButton As Button = sender
        clickedButton.Text = "...button clicked..."
        clickedButton.Enabled = False
 
        ' Display the greeting label text.
        GreetingLabel.Visible = True
    End Sub

</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>Button Example</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
      <h3>Simple Button Example</h3>
     
      <asp:Button id="Button1"
           Text="Click here for greeting..."
           OnClick="GreetingBtn_Click" 
           runat="server"/>
      <br />
      <br />
      <asp:Label ID="GreetingLabel" runat="server" 
                 Visible="false" Text="Hello World!" />
    </div>
    </form>
</body>
</html>

Poznámky

Událost Click je vyvolána při kliknutí na Button ovládací prvek. Tato událost se běžně používá, když k ovládacímu Button prvku není přidružený žádný název příkazu (například k tlačítku Odeslat).

Další informace o zpracování událostí najdete v tématu Zpracování a vyvolávání událostí.

Platí pro

Viz také