动态添加一个按钮 可不知道怎么给那个按钮写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事件 不知道  麻烦各位帮忙  随便给个获得 上面所填写的值的事件咯
    }
    }

解决方案 »

  1.   

    //根据配置信息生成按钮
            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;
            }
      

  2.   

    我这也是动态添加 也有Click事件 你看看 也许有些帮助
      

  3.   

    不知道你是在客户端,还是在服务器。下面都列出了。客户端:
    this.ButtonName.Attributes.Add("chick", "string value");
    服务器:(直接在.cs中写)
    protected void ButtonName_Click(object sender, EventArgs e)
    {}
      

  4.   

    Button b1 = new Button();
    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)
    {
       // ... 
    }
      

  5.   

    Button b1 = new Button();
    b1.Click += new System.EventHandler(b1_Click);
    这就是事件啊。
      

  6.   

    private void btnCreate_Click(object sender, System.EventArgs e)
        {
    //我想这句是LZ你需要的;
            TextBox T1 = (TextBox)Page.FindControl("txtCreate");
            lblMsg.Text = T1.Text;
        }
      

  7.   

    在点击事件里写了个遍历 可 下一步怎么获取那些值 不记得怎么写了 还请帮忙
        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)
                    {
                       //这里改写什么啊? 请问!!
                        
                    }
                }
            }
        }
      

  8.   

    那么多foreach 啊 直接找就可以了吧
      

  9.   

    每个控件 都给一个IDTextBox t1 = (TextBox)TableID.FindControl("ID");这样就能找到控件了
    然后就可以操作了啊
      

  10.   

    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.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)
                    {
                 // 全部代码 在这   可这里不知道怎么获得上面的值   还请指点
                    }
                }
            }
        }