I want to handle click event of link button which is dynamically created.
But i am not getting btn.click for it.
I have following code:
Public Sub test()
Dim row As New HtmlTableRow()
Dim cell As New HtmlTableCell()
For i = 0 To 10
row = New HtmlTableRow()
For j = 0 To 3
cell = New HtmlTableCell()
cell.InnerText = "m"
Dim btn1 As New LinkButton
btn1.ID = i
cell.Controls.Add(btn1)
row.Cells.Add(cell)
Next
tableContent.Rows.Add(row)
Next
End Sub
C# Code:
public void test()
{
HtmlTableRow row = new HtmlTableRow();
HtmlTableCell cell = new HtmlTableCell();
for (i = 0; i <= 10; i++) {
row = new HtmlTableRow();
for (j = 0; j <= 3; j++) {
cell = new HtmlTableCell();
cell.InnerText = "m";
LinkButton btn1 = new LinkButton();
btn1.ID = i;
cell.Controls.Add(btn1);
row.Cells.Add(cell);
}
tableContent.Rows.Add(row);
}
}
Not getting intellisence on btn1.click:

EDIT:

Answer in c# can also help me.
For VB.NET, type AddHandler btn1. and then you should see the Click event in the Intellisense, like this:
AddHandler btn1.Click, AddressOf Me.LinkButton_OnClick
Since you have dynamic content (table), you will need to rebuild the table on every page load, not just the first. The reason for this is that the Page_Load happens before the link button click event, so by the time the click event happens the table needs to have been recreated; otherwise your click event handler will try to interact with content that is not there.
Read ASP.NET Page Life Cycle Overview for more information about the page life cycle and all the events and their order.
In C# you can do:
1. Declare the handler
protected void btn1_Click(object sender, EventArgs e)
{
}
2. Assign the handler:
LinkButton btn1 = new LinkButton();
btn1.Click += new EventHandler(btn1_Click);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With