从控件动态创建表单并提交单击

时间:2014-07-11 18:14:28

标签: c# asp.net controls

为什么btnSave_Click没有开火?当我点击它但不跳入处理程序时它会回发。

        if (Session["mytable"] != null)
            pnlContent.Controls.Add((Table)Session["mytable"]);
        else
        {
            Table table = new Table();
            foreach (var item in Items)
            {
                TableRow row = new TableRow();
                table.Rows.Add(row);
                if (item.ColumnTypeName == "String")
                {
                    TableCell cell = new TableCell();
                    row.Cells.Add(cell);
                    cell.Controls.Add(new LiteralControl(item.ColumnName));

                    TextBox textbox = new TextBox();
                    textbox.ID = item.ColumnName;

                    TableCell cell2 = new TableCell();
                    row.Cells.Add(cell2);
                    cell2.Controls.Add(textbox);
                }
            }

            LinkButton btnSave = new LinkButton();
            btnSave.ID = "btnSave";
            btnSave.Click += new EventHandler(btnSave_Click);
            btnSave.Text = "Submit";

            TableRow row1 = new TableRow();
            table.Rows.Add(row1);
            TableCell cell3 = new TableCell();
            row1.Cells.Add(cell3);
            cell3.Controls.Add(btnSave);

            pnlContent.Controls.Add(table);

            Session["mytable"] = table;
        }

    protected void btnSave_Click(object sender, EventArgs e)
    {
        //TADAA
    }

0 个答案:

没有答案