动态添加一个按钮 可不知道怎么给那个按钮写Click事件麻烦各位帮帮忙,写个获得填写值的事件
先谢了
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
//第一行
Label l1 = new Label();
l1.Text = "用户名";
TextBox t1 = new TextBox();
TableCell tr1_tc1 = new TableCell();
TableCell tr1_tc2 = new TableCell();
tr1_tc1.Controls.Add(l1);
tr1_tc2.Controls.Add(t1);
TableRow tr1 = new TableRow();
tr1.Cells.Add(tr1_tc1);
tr1.Cells.Add(tr1_tc2);
//第二行
Label l2 = new Label();
l2.Text = "密码";
TextBox t2 = new TextBox();
t2.TextMode = TextBoxMode.Password;
TableCell tr2_tc1 = new TableCell();
TableCell tr2_tc2 = new TableCell();
tr2_tc1.Controls.Add(l2);
tr2_tc2.Controls.Add(t2); TableRow tr2 = new TableRow();
tr2.Cells.Add(tr2_tc1);
tr2.Cells.Add(tr2_tc2); Button b1 = new Button();
b1.Text = "登录";
TableCell tr3_tc1 = new TableCell();
tr3_tc1.Controls.Add(b1);
TableRow tr3 = new TableRow();
tr3.Cells.Add(tr3_tc1);
Table1.Rows.Add(tr1);
Table1.Rows.Add(tr2);
Table1.Rows.Add(tr3); //怎么添加Click事件 不知道 麻烦各位帮忙 随便给个获得 上面所填写的值的事件咯
}
}
先谢了
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
//第一行
Label l1 = new Label();
l1.Text = "用户名";
TextBox t1 = new TextBox();
TableCell tr1_tc1 = new TableCell();
TableCell tr1_tc2 = new TableCell();
tr1_tc1.Controls.Add(l1);
tr1_tc2.Controls.Add(t1);
TableRow tr1 = new TableRow();
tr1.Cells.Add(tr1_tc1);
tr1.Cells.Add(tr1_tc2);
//第二行
Label l2 = new Label();
l2.Text = "密码";
TextBox t2 = new TextBox();
t2.TextMode = TextBoxMode.Password;
TableCell tr2_tc1 = new TableCell();
TableCell tr2_tc2 = new TableCell();
tr2_tc1.Controls.Add(l2);
tr2_tc2.Controls.Add(t2); TableRow tr2 = new TableRow();
tr2.Cells.Add(tr2_tc1);
tr2.Cells.Add(tr2_tc2); Button b1 = new Button();
b1.Text = "登录";
TableCell tr3_tc1 = new TableCell();
tr3_tc1.Controls.Add(b1);
TableRow tr3 = new TableRow();
tr3.Cells.Add(tr3_tc1);
Table1.Rows.Add(tr1);
Table1.Rows.Add(tr2);
Table1.Rows.Add(tr3); //怎么添加Click事件 不知道 麻烦各位帮忙 随便给个获得 上面所填写的值的事件咯
}
}
解决方案 »
- asp.net发送电子邮件问题???
- 登陆框 当session失效时.................
- 页面上有一Iframe调用另一页面,另一页面上使用了lightbox,如何使弹出的图片后背景遮挡父页面???
- 请问"Web 窗体设计器生成的代码"这一大段代码是怎么来的
- .NET2005如何限制编译生成的DLL名称?
- 问一个简单问题,有关<TABLE>的
- 使用GridView自带的编辑删除出问题了
- 太急了,关于DataSet.Tables中的Columns中的属性不见了,给分不是问题,
- 在编写模块时遇到的问题,大家指点一二
- 高手请快进
- 图片上传的问题
- 求救?页面上有三个文本框textbox1,textbox2,textbox3和一个查询按钮,任意一个或组合输入条件后,请问查询代码或算法?
private void MakePicBox()
{
//绘制新的Button
int showPicBoxNum = 0;
for (int i = 0; i < configInfo.channelList.Count; ++i)
{
if (configInfo.channelList[i].isShow)
{
showPicBoxNum++;
picBox = new PictureBox();
picBox.BorderStyle = BorderStyle.None;
picBox.Width = 36;
picBox.Height = 25;
picBox.Name = configInfo.channelList[i].icoIndex.ToString();
picBox.Tag = true;
picBox.Image = global::AutonomyClient.Properties.Resources.DBButtonUnLight;
picBox.Left = this.picBox.Width * (showPicBoxNum + 3) + 6;
picBox.Top = pictureBox3.Top;
picBox.Cursor = Cursors.Hand;
picBox.Enabled = false;
picBox.Click += new System.EventHandler(this.PicBox_Click);
picBox.MouseHover += new EventHandler(picBox_MouseHover);
this.Controls.Add(picBox);
this.Refresh();
}
}
}//PicBox的单击事件
private void PicBox_Click(object sender, System.EventArgs e)
{
//MessageBox.Show(((PictureBox)sender).Name);
((PictureBox)sender).Image = global::AutonomyClient.Properties.Resources.DBButtonDown;
((PictureBox)sender).Refresh(); if (sform != null)
{
sform.Close();
sform = null;
} resultForm = new ResultForm(this, int.Parse(((PictureBox)sender).Name), "搜索结果");
resultForm.sendResultFromClosed = new ResultFormClosed(DealResultFormClosed);
resultForm.Show();
MainForm.resultFormIsShowNow = true;
}
this.ButtonName.Attributes.Add("chick", "string value");
服务器:(直接在.cs中写)
protected void ButtonName_Click(object sender, EventArgs e)
{}
b1.Text = "登录";
TableCell tr3_tc1 = new TableCell();》》》
Button b1 = new Button();
b1.Click += new EventHandler(b1_Click); // 在这里
b1.Text = "登录";
TableCell tr3_tc1 = new TableCell();
// 事件处理程序
protected void b1_Click(object sender, EventArgs e)
{
// ...
}
b1.Click += new System.EventHandler(b1_Click);
这就是事件啊。
{
//我想这句是LZ你需要的;
TextBox T1 = (TextBox)Page.FindControl("txtCreate");
lblMsg.Text = T1.Text;
}
protected void b1_Click(object sender, EventArgs e)
{ foreach (TableRow tr in Table1.Rows)
{
foreach (TableCell tc in tr.Cells)
{
foreach (Control c in tc.Controls)
{
//这里改写什么啊? 请问!!
}
}
}
}
然后就可以操作了啊
{
protected void Page_Load(object sender, EventArgs e)
{
//第一行
Label l1 = new Label();
l1.Text = "用户名";
TextBox t1 = new TextBox();
TableCell tr1_tc1 = new TableCell();
TableCell tr1_tc2 = new TableCell();
tr1_tc1.Controls.Add(l1);
tr1_tc2.Controls.Add(t1);
TableRow tr1 = new TableRow();
tr1.Cells.Add(tr1_tc1);
tr1.Cells.Add(tr1_tc2);
//第二行
Label l2 = new Label();
l2.Text = "密码";
TextBox t2 = new TextBox();
t2.TextMode = TextBoxMode.Password;
TableCell tr2_tc1 = new TableCell();
TableCell tr2_tc2 = new TableCell();
tr2_tc1.Controls.Add(l2);
tr2_tc2.Controls.Add(t2); TableRow tr2 = new TableRow();
tr2.Cells.Add(tr2_tc1);
tr2.Cells.Add(tr2_tc2); Button b1 = new Button();
b1.Click += new EventHandler(b1_Click);
b1.Text = "登录";
TableCell tr3_tc1 = new TableCell();
tr3_tc1.Controls.Add(b1);
TableRow tr3 = new TableRow();
tr3.Cells.Add(tr3_tc1);
Table1.Rows.Add(tr1);
Table1.Rows.Add(tr2);
Table1.Rows.Add(tr3);
}
protected void b1_Click(object sender, EventArgs e)
{ foreach (TableRow tr in Table1.Rows)
{
foreach (TableCell tc in tr.Cells)
{
foreach (Control c in tc.Controls)
{
// 全部代码 在这 可这里不知道怎么获得上面的值 还请指点
}
}
}
}