0

I am generating dynamic table (testtable) and simultaneously I am generating LinkButton in last column of each row which doesn't get fired when I click on it. all("Users") returns DataTable. Please Help.

Markup

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

    <ContentTemplate>

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

    </ContentTemplate>

</asp:UpdatePanel>

Code

    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
}
  • Because of you have use update panel that's why it will not post-back the page. You need to post-back the page forcefully. or You should have to remove update panel . – Ravikumar Jul 21 '17 at 10:19
  • Please stop using UpdatePanels and try to make request from javascrip/jquery etc. UpdatePanels are frustrating. – Imad Jul 21 '17 at 10:30
  • Thanks for fast reply guys. @Ravikumar, you were right it works when I remove update panel. – AbdulAziz Nurov Jul 21 '17 at 10:49
  • I just started to like UpdatePanels now I have to remove it ;( What is the best practice to replace UpdatePanel? – AbdulAziz Nurov Jul 21 '17 at 10:55
  • @Ravikumar can you post your comment as an answer so that I can mark it as a correct answer? – AbdulAziz Nurov Jul 21 '17 at 11:01

1 Answers1

0

Because of you have use update panel that's why it will not post-back the page. You need to post-back the page forcefully. or You should have to remove update panel .

Ravikumar
  • 613
  • 1
  • 9
  • 22