add an onclick event to a dynamically created linkbutton
<p>What I'm trying to accomplish is to set my dynamically created linkbutton with a onClick command so when click it will run a method in the code behind. This is my code:</p>

<pre><code>protected void Page_Init(object sender, EventArgs e)
{
    LoadLeftSide();
}

private void LoadLeftSide()
{
    string filepath = Server.MapPath("DataSource.xml");
    List&lt;Post&gt; list = PostHelper.GetAllPosts(filepath);
    HtmlTable table = FindControl("tbl") as HtmlTable;

    HtmlTableRow hearderrow = new HtmlTableRow();
    HtmlTableCell heardercell = new HtmlTableCell();     

    heardercell.InnerText = "Posts:";       
    hearderrow.Cells.Add(heardercell);
    table.Rows.Add(hearderrow);

    foreach (Post p in list)
    {
        HtmlTableRow row = new HtmlTableRow();
        HtmlTableCell cell1 = new HtmlTableCell();

        LinkButton lnkPost = new LinkButton();
        lnkPost.ID =string.Format("{0}" ,Guid.NewGuid());
        lnkPost.Attributes.Add("runat", "server");
        lnkPost.Text = p.Title;
       // lnkPost.CommandName = p.Id.ToString();
       // lnkPost.CommandArgument = p.Id.ToString();
        //lnkPost.Command += new CommandEventHandler(this.onLinkClick);
        lnkPost.Click += new EventHandler(this.onLinkClick);   

        cell1.Controls.Add(lnkPost);            
        row.Cells.Add(cell1);
        table.Rows.Add(row);

    }
    table.DataBind();

}

protected void onLinkClick(object sender, EventArgs e)
{
    string filepath = Server.MapPath("DataSource.xml");
    int id = 1;
    Post post=PostHelper.GetPostById(id, filepath);
    lblDescription.Text = post.Description;
}
</code></pre>
