给你一段
HtmlTableRow row3 = new HtmlTableRow();
row3.Align = "center";
Button Btn = new Button();
Btn.ID = "Btn_0";
Btn.Width = 60;
Btn.Height = 20;
Btn.Text = "确 定";
HtmlTableCell cell20 = new HtmlTableCell();
cell20.ColSpan = 2;
cell20.Controls.Add(Btn);
row3.Cells.Add(cell20);
ta.Rows.Add(row3);
Btn.Click +=new EventHandler(NewButton_Click);
HtmlTableRow row3 = new HtmlTableRow();
row3.Align = "center";
Button Btn = new Button();
Btn.ID = "Btn_0";
Btn.Width = 60;
Btn.Height = 20;
Btn.Text = "确 定";
HtmlTableCell cell20 = new HtmlTableCell();
cell20.ColSpan = 2;
cell20.Controls.Add(Btn);
row3.Cells.Add(cell20);
ta.Rows.Add(row3);
Btn.Click +=new EventHandler(NewButton_Click);
//====================
//WebForm2.aspx:
//====================<%@ Page language="c#" Codebehind="WebForm2.aspx.cs" AutoEventWireup="false" Inherits="WebApplication2.WebForm2" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<HTML>
<HEAD>
<title>WebForm2</title>
<meta name="GENERATOR" Content="Microsoft Visual Studio 7.0">
<meta name="CODE_LANGUAGE" Content="C#">
<meta name="vs_defaultClientScript" content="JavaScript">
<meta name="vs_targetSchema" content="http://schemas.microsoft.com/intellisense/ie5">
</HEAD>
<body MS_POSITIONING="GridLayout">
<form id="MyForm" method="post" runat="server">
</form>
</body>
</HTML>//===========================
//WebForm2.aspx.cs:
//===========================
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;namespace WebApplication2
{
/// <summary>
/// WebForm2 的摘要说明。
/// </summary>
public class WebForm2 : System.Web.UI.Page
{
protected HtmlForm MyForm;
private void Page_Load(object sender, System.EventArgs e)
{
if (!IsPostBack)
{
Button btn=new Button();
btn.Text="动态添加的按钮";
MyForm.Controls.Add(btn); }
} #region Web Form Designer generated code
override protected void OnInit(EventArgs e)
{
//
// CODEGEN:该调用是 ASP.NET Web 窗体设计器所必需的。
//
InitializeComponent();
base.OnInit(e);
}
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.ID = "MyForm1";
this.Load += new System.EventHandler(this.Page_Load); }
#endregion
}
}