C# Dynamically created LinkButton Command Event Handler

Posted by spdevsolutions on Stack Overflow See other posts from Stack Overflow or by spdevsolutions
Published on 2008-09-26T18:35:02Z Indexed on 2010/04/01 9:33 UTC
Read the original article Hit count: 780

Filed under:
|
|

So I have a weird situation here... I have an System.Web.UI.WebControls.WebParts.EditorPart class. It renders a "Search" button, when you click this button, it's clickHandler method does a DB search, and dynamically creates a LinkButton for each row it returns, sets the CommandName and CommandArgument properties and adds a CommandEventHandler method, then adds the LinkButton control to the page.

The problem is, when you click a LinkButton, its CommandEventHandler method is never called, it looks like the page just posts back to where it was before the ORIGINAL "Search" button was pressed.

I have seen postings saying that you need to add the event handlers in OnLoad() or some other early method, but my LinkButtons haven't even been created until the user tells us what to search for and hits the "Search" button... Any ideas on how to deal with this?

Thanks!

© Stack Overflow or respective owner

Related posts about c#

Related posts about ASP.NET