在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
using System; using System.Data; using System.Configuration; using System.Web; using System.Web.Security; using System.Web.UI; using System.Web.UI.WebControls; using System.Web.UI.WebControls.WebParts; using System.Web.UI.HtmlControls; public partial class _Default : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { //创建一个文本框 TextBox tbxName = new TextBox(); tbxName.ID = "tbxName"; tbxName.Text = "OK"; this.form1.Controls.Add(tbxName); //创建一个按钮 Control c = ParseControl("<asp:Button Text = '按我' ID = 'myButton' runat = 'server' />"); this.form1.Controls.Add(c); //创建一个按钮事件 Button myButton = (Button)Page.FindControl("myButton"); myButton.Command += new CommandEventHandler(this.myButton_Click); } protected void myButton_Click(Object sender, EventArgs e) { TextBox t = (TextBox)Page.FindControl("tbxName"); Response.Write(t.Text); } } |
请发表评论