0

On clciking a button in the page , I am adding an user control in to a place holder of the page. The user control has a gridview which has a link button as template field and has a click event associated with it.

When I click the link button inside the gridview , the link button click event is not fired and also the user control disappears in the page.

Please suggest a solution

  • Sounds like the button is doing a postback and your not doing a databind on the usercontroll, but you are not giving us much to go by, could you maybe post some code. – Roise Sep 20 '12 at 14:42

2 Answers2

0

--You need to recreate all your dynamic controls at the early enough in the page lifecycle (page_load/page_init), so the asp.net will detect events and attach them.

try this knowledge post http://support.microsoft.com/kb/317794

Why don't events of dynamically added user control fire on postback?

Community
  • 1
  • 1
Sathish Raja
  • 131
  • 3
0

You need to recreate your dynamic controls on every postback - remember a new class instance of your page is created every postback, so any dynamic controls you created the previous time will need to be recreated.

see this article

and this one

Community
  • 1
  • 1
Richard Friend
  • 15,800
  • 1
  • 42
  • 60