Problem:
When I click my linkbutton the form gets submitted, but it doesn't execute the postback function. It also doesn't execute the click function. These two don't get hit at all.
Workaround
Remove the ID from the linkbutton. In this case the click function get executed.
The button is dynamically added through this code:
LinkButton l = new LinkButton();
l.CssClass = "clause show-modalbox";
l.Click += clauseButton_Click;
l.Visible = true;
l.ID = "LinkButton_0";
l.Text = "C";
EDIT: I changed the ID to a static string, so that on postback the ID will be guaranteed the same.
EDIT 2: From the comments below: My Page_Init and Page_Load are not executed either on postback, they are properly executed when I leave out the ID of the button however.
EDIT 3: I was convinced this problem was related to my code because it didn't happen on other pages. Because of this I left out two important details:
- The page has a masterpage
- The content was rendered inside an updatepanel
See my answer below for the solution.