Page

How to use Click event in Button control

// Default.aspx //

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="Default" %>

 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">  
 
<html xmlns="http://www.w3.org/1999/xhtml">  
<head runat="server">  
   <title>Button example: how to use Click event in Button control</title>  
</head>  
<body>  
   <form id="form1" runat="server">  
   <div>  
       <asp:Label ID="Label1" runat="server" Font-Size="Large" ForeColor="Crimson"></asp:Label>  
       <br /><br />  
       <asp:Button ID="Button1" runat="server" Text="Button1" OnClick="Button1_Click" />  
       <asp:Button ID="Button2" runat="server" Text="Button2" OnClick="Button2_Click" />  
   </div>  
   </form>  
</body>  
</html>  


// Default.aspx.cs //

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class Default : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {


    }
  protected void Button1_Click(object sender, System.EventArgs e)  
    {  
        Label1.Text = "You clicked Button1";  
    }  
  
    protected void Button2_Click(object sender, System.EventArgs e)  
    {  
        Label1.Text = "You clicked Button2";  
    }  
}


// OUTPUT //




No comments:

Post a Comment