3、Web 窗体的基本控件——按钮控件(Button,LinkButton)
按钮控件(Button,LinkButton)
前端
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm4.aspx.cs" Inherits="WebApplication2.WebForm4" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title></title>
</head>
<body>
<form id="form1" runat="server">
<asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
<br />
<br />
<br />
<br />
<br />
<br />
<div>
<asp:Button ID="Button1" runat="server" Text="Button" OnClick="Button1_Click" /> //普通的按钮
<br />
<asp:LinkButton ID="LinkButton1" runat="server" OnClick="LinkButton1_Click">LinkButton</asp:LinkButton> //Link 类型的按钮
<br />
<br />
<br />
<br />
<br />
</div>
</form>
</body>
</html>
后端
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace WebApplication2
{
public partial class WebForm4 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
Label1.Text = "普通按钮被触发"; //输出信息
}
protected void LinkButton1_Click(object sender, EventArgs e)
{
Label1.Text = "连接按钮被触发"; //输出信息
}
}
}
预览