Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Assign Event Programmatically to Child Inside FormView

I realize you can declaratively assign an event handler to a child control inside a formview by adding its attribute on the aspx page (i.e. onclick="Button_Click"), but if I wanted to do this programmatically, how would I go about it? That control isn't going to be found through FormView.FindControl in the Page's Init or Load events, so it can't be assigned in those stages. The DataBound event of the FormView will allow you to find the control, but is inappropriate, since that only happens once, and then the event won't always be bound, and it won't fire. I'm not asking because I can't get around it, I just wanted to know how it could be done.

Cheers.

like image 381
Matt Avatar asked Dec 18 '09 17:12

Matt


2 Answers

You should use the FormView's ItemCreated Event. It occurs after all rows are created, but before the FormView is bound to data.

Look at this MSDN page for more information

like image 198
Gabriel McAdams Avatar answered Oct 05 '22 19:10

Gabriel McAdams


in c# this is accomplished via:
this.btnProcess.Click += new EventHandler(btnProcess_Click);

like image 38
KellCOMnet Avatar answered Oct 05 '22 18:10

KellCOMnet