views:

8

answers:

1

Hi guys,

I have a datalist and want to dynamically add buttons to it. I am using the OnItemCommand datalist event and setting the CommandName/ CommandArgument attributes of the button. However I am having trouble with handling the button click - does not seem to fire.

It works when I declared a button on the aspx page, but not for buttons that are dynamically created.

I hope this makes sense, and any help would be great.

Thanks

A: 

You can only create dynamic controls on PreInit or Init if you want to handle associated events. Otherwise, on postback, they won't exist at the moment of event handling and because of that, your handler method won't be called.

Internet is full of resources about how to handle dynamic controls. Let me know if you need any reference.

Claudio Redi