When you create a dynamic control, you cannot directly create the click event of this control. In your case, you must follow this path. Add javascript to redirect the contactus.aspx page.
System.Web.UI.WebControls.LinkButton lbView = new System.Web.UI.WebControls.LinkButton(); lbView.Text = "<br />" + "View"; btn.OnClientClick = "return RedirectTo();"; // You need to add javascript event tc.Controls.Add(lbView); tr.Cells.Add(tc); // javascript <script> function RedirectTo() { window.location.href = 'contactus.aspx'; return false; } </script>
Try it. Hope this works for you.
source share