LInkBut​​ton 未触发事件

LInkButton is not firing event

我正在生成动态 table (testtable),同时我在每行的最后一列生成 LinkButton,当我点击它时不会被触发。 all("Users") returns DataTable。请帮助。

标记

 <asp:UpdatePanel ID="MainUpdatePanel" runat="server" Visible="false">

    <ContentTemplate>

        <asp:Table ID="testTable" runat="server" />

    </ContentTemplate>

</asp:UpdatePanel>

代码

    protected override void OnInit(EventArgs e)
    {
        base.OnInit(e);

        TableHeaderRow tHeaderRow = new TableHeaderRow();
        tHeaderRow.TableSection = TableRowSection.TableHeader;
        testTable.Rows.Add(tHeaderRow);

        foreach (DataColumn column in all("Users").Columns)
        {
            TableHeaderCell tHeaderCell = new TableHeaderCell();
            tHeaderCell.Text = column.ColumnName;
            tHeaderRow.Cells.Add(tHeaderCell);
        }

        TableHeaderCell tShowHeaderCell = new TableHeaderCell();
        tHeaderRow.Cells.Add(tShowHeaderCell);

        string id = "";
        int i = 0;


        foreach (DataRow row in all("Users").Rows)
        {


            TableRow tRow = new TableRow();
            tRow.TableSection = TableRowSection.TableBody;

            testTable.Rows.Add(tRow);

            foreach (DataColumn column in all("Users").Columns)
            {
                TableCell tCell = new TableCell();
                tCell.Text = row[column.ColumnName].ToString();
                tRow.Cells.Add(tCell);

                if (column.ColumnName == "id")
                    id = row[column.ColumnName].ToString();
            }

            LinkButton showlink = new LinkButton();
            showlink.Text = "<i class='icon-file'></i>";
            showlink.ID = "linkShow" + "_" + i.ToString();
            showlink.CssClass = "tip-top";
            showlink.CommandArgument = id;


            TableCell tShowCell = new TableCell();
            tRow.Cells.Add(tShowCell);
            tShowCell.Controls.Add(showlink);
            showlink.Click += new EventHandler(Show);
            i++;
        }

    }

protected void Show(object sender, EventArgs e)
{
    // Do stuff
}

因为您使用了更新面板,所以它不会 post-back 页面。您需要post-强力支持该页面。或者您应该删除更新面板。