Hi,
I am trying to create an ASP.NET table programmatically and I want some of the cells to contain a LinkButton with an OnClick event handler associated with it.
The thing is that when I add the event handler programmatically it does not work, but adding it manually on a static LinkButton on the page itself it works fine. (Simplified examples below)
Has anyone experienced the same? and found a solution?
Kind regards,
Lars Betak Tengstedt
Edlund A/S, Denmark
THIS WORKS (DoStuff is executed):
===========
mytable.aspx:
-------------
<asp:table>
<asp:tablerow>
<asp:tablecell>
<asp:linkbutton OnClick=DoStuff>My Link</asp:linkbutton>
</asp:tablecell>
</asp:tablerow>
</asp:table>
mytable.aspx.cs:
----------------
protected void DoStuff(object sender, System.EventArgs e){...}
THIS DOES NOT WORK (DoStuff is NOT executed)
=====================
mytable.aspx:
-------------
<asp:table id=mytable>
<asp:tablerow>
<asp:tablecell>
</asp:tablecell>
</asp:tablerow>
</asp:table>
mytable.aspx.cs:
----------------
Page_Load(...)
{
LinkButton myLB = new LinkButton();
myLB.ID = "myLB";
myLB.Click += new System.EventHandler(this.DoStuff);
myLB.Text = "My Link";
myLB.EnableViewState = true;
mytable.Rows[0].Cells[0].Controls.Add(myLB);
}
protected void DoStuff(object sender, System.EventArgs e){...}
I am trying to create an ASP.NET table programmatically and I want some of the cells to contain a LinkButton with an OnClick event handler associated with it.
The thing is that when I add the event handler programmatically it does not work, but adding it manually on a static LinkButton on the page itself it works fine. (Simplified examples below)
Has anyone experienced the same? and found a solution?
Kind regards,
Lars Betak Tengstedt
Edlund A/S, Denmark
THIS WORKS (DoStuff is executed):
===========
mytable.aspx:
-------------
<asp:table>
<asp:tablerow>
<asp:tablecell>
<asp:linkbutton OnClick=DoStuff>My Link</asp:linkbutton>
</asp:tablecell>
</asp:tablerow>
</asp:table>
mytable.aspx.cs:
----------------
protected void DoStuff(object sender, System.EventArgs e){...}
THIS DOES NOT WORK (DoStuff is NOT executed)
=====================
mytable.aspx:
-------------
<asp:table id=mytable>
<asp:tablerow>
<asp:tablecell>
</asp:tablecell>
</asp:tablerow>
</asp:table>
mytable.aspx.cs:
----------------
Page_Load(...)
{
LinkButton myLB = new LinkButton();
myLB.ID = "myLB";
myLB.Click += new System.EventHandler(this.DoStuff);
myLB.Text = "My Link";
myLB.EnableViewState = true;
mytable.Rows[0].Cells[0].Controls.Add(myLB);
}
protected void DoStuff(object sender, System.EventArgs e){...}