0

I'm adding a control (linkbutton) dynamically using ParseControl and it's fine except when I specify an event handler.

If I use:

Dim c As Control = ParseControl("<asp:LinkButton id=""btnHide"" runat=""server"" text=""Hide"" OnClick="btnHide_Click" />")

it correctly adds the control to the page but the click event doesn't fire. If instead I find the control in the controls collection and manually wire up the event it works fine. I've tried loading in both Page_Init and Page_Load and it's the same thing either way.

Any ideas?

Edit:

In reality I'm not only parsing a single linkbutton in the code, I'm parsing a bunch of text that includes linkbuttons, checkboxes etc. I wonder if that has any bearing on it not performing as expected?

Richard Edwards
  • 1,379
  • 1
  • 17
  • 30

1 Answers1

0

Have you try this:

Dim c As LinkButton = ParseControl("<asp:LinkButton id=""btnHide"" runat=""server"" text=""Hide""  />")
AddHandler c.Click, AddressOf btnHide_Click
alejandrobog
  • 2,091
  • 14
  • 20
  • Yes, I mentioned that I can do that if I need to but I just wanted to get to the bottom of why it doesn't work the other way. I'd like to simplify it as much as possible. One other thing I didn't mention is that I'm not just parsing a single linkbutton, I'm parsing a bunch of code to create multiple buttons in the same ParseControl statement. – Richard Edwards Apr 17 '10 at 12:52