What I'm trying to do is set up a dynamically created link using the onClick command, so clicking on it will start the method in the code. This is my code:
protected void Page_Init(object sender, EventArgs e) { LoadLeftSide(); } private void LoadLeftSide() { string filepath = Server.MapPath("DataSource.xml"); List<Post> 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;
alina source share