25,980
社区成员
发帖
与我相关
我的任务
分享
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="TestPage02.aspx.cs" Inherits="TestPage02" %>
<!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>无标题页</title>
</head>
<body>
<form id="form1" runat="server">
<asp:Panel ID="divTest" runat="server"></asp:Panel>
<asp:Button ID="btTest" Text="测试" runat="server" onclick="btTest_Click" />
<br />
<asp:Label ID="lblTest" runat="server"></asp:Label>
</form>
</body>
</html>
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
public partial class TestPage02 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void btTest_Click(object sender, EventArgs e)
{
LinkButton lnkBt = new LinkButton();
lnkBt.Text = "测试1";
lnkBt.CommandArgument = "参数001";
lnkBt.Click += new EventHandler(lnkBt_Click);
divTest.Controls.Add(lnkBt);
}
protected void lnkBt_Click(object sender, EventArgs e)
{
lblTest.Text = (sender as LinkButton).CommandArgument;
}
}